Slashdot Mirror


Bad Programming Habits We Secretly Love (infoworld.com)

snydeq writes: Breaking the rules can bring a little thrill — and sometimes produce better, more efficient code. From the article: 'The rules are more often guidelines or stylistic suggestions, not hard-and-fast rules that must be obeyed or code death will follow. Sure, your code might be ridiculed, possibly even publicly, but the fact that you're bucking conventions adds a little bit of the thrill to subverting, even inadvertently, what amounts more often than not to the social mores of pleasant code. To make matters more complex, sometimes it's better to break the rules. (Shhhh!) The code comes out cleaner. It may even be faster and simpler.' What bad programming habits can't you (or won't you) break?

3 of 497 comments (clear)

  1. Copy and Paste. by jellomizer · · Score: 4, Informative

    Sometimes I will copy and paste a function and just do some minor tweaks were I could have just added a parameter.
    Why do I do this? Readability. Having a function called SplitPersonName(string name) and another one called SplitCompanyName(string name) So when I run the function it will be easily readable, as well if there is a bug in one of the fuctions but it works fine for the other. I can just change that one function without having to unit test other parts that could have been effected.

    Also I avoid too much Classes that are extended from other classes, that tends to add confusion on where a particular code is being called if you are debugging it from the middle of the class structure.

    It is OK to break rules, but you should have a good reason to do so. Also you should feel free to not break the rules when you do not have a good reason to do so.
     

    --
    If something is so important that you feel the need to post it on the internet... It probably isn't that important.
  2. Re:"The code comes out cleaner"? by nitehawk214 · · Score: 4, Informative

    I would not consider non-working code as clean.

    --
    I'm a good cook. I'm a fantastic eater. - Steven Brust
  3. Re:You're the problem by coats · · Score: 3, Informative
    Donald Knuth has stated that he is in favor of these kinds of "structured GOTO's".

    There is a theorem that in general, GOTO's can be replaced by WHILE's and flags. What is generally not mentioned is that in the general case, the size of the resulting code grows exponentially in terms of the size of the original code. ;-(

    As it happens, we do not get exponential growth for the "break out of the loop" cases...

    --
    "My opinions are my own, and I've got *lots* of them!"