View Full Version : Is there such a thing as wrong coding, even when it works?

06-04-2007, 04:01 PM
I've been thinking about this for a few days now. Wondering around different websites you always see someone saying 'You've done that wrong' or 'Why did you do it like that when you could have done it like this'.

Sometimes when I'm sat down and doing some coding that I haven't got any help for I often wonder if what I have done is the 'legit' way, even if the coding ends up working.

So what do you think?

Is there such a thing as wrong coding, even when it works?

06-04-2007, 05:40 PM
there is 100 ways to write the same code (more server side scripting really than HTML) but as a programmer your obligated to write robust, economical code which is easy to use and easy to pass on to others with a minimum of handovers. I could write code differently from the next person and we both would have a valid argument for our methods. Both would do the job and both would be valid so who is right?

take this example for instance

if($var == 1){
//do this
}elseif($var == 2){
//do this
}elseif($var == 3){
//do this


case '1': /*do this*/; break;
case '2': /*do this*/; break;
case '3': /*do this*/; break;

both of thos examples do the same job but which is better?
i would prefer the switch statement personaly but its down to taste. (it looks nicer! sad eh)

I would say this.. If it works and it doesnt throw an error then its not wrong but listen to others when they say -> "do it this way because it only takes 7 lines of code instead of 11".

7 lines is better than 11 right

06-05-2007, 08:56 AM
there are so many ways to do the same thing in the development world (esp with CSS & html)

some ways might be cleaner, more efficient, and faster loading (so therefor better)

so long as you can justify why you did it that way, then it deffinatly comes down to personal taste (and the style you are use to coding in)

but the whole of idea of feedback is to improve on what you already (hopefully) know. So its still good to get constructive criticism