Is There Right Code and Wrong Code?

20 בינואר 2009

5 תגובות

Today I argued with my boss about a piece of code. I said that the code is wrong because it didn’t do what it had declared to do (it’s named “GetMMM” and it actually added stuff too), my boss said that this was the right place for the code because it would prevent future bugs.

My questions are simple –

  • Can a piece of code, that does not follow the “rational” coding approach, be called “wrong code”?
  • Should a piece of code that prevents bugs, and breaks all coding standards while doing so, be left in the code?

What do you say?

kick it on

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *

5 תגובות

  1. BlackWasp20 בינואר 2009 ב 22:53

    It's a difficult one to judge without seeing the code. That aside, my first reaction would be that the naming of the method may require consideration. Certainly if the method is hidden away, a developer maintaining the code may misjudge calls to GetMMM, assuming it is a read-only operation. Also, unless MMM is an industry acronym, this may need consideration too.

    Again, I can't see the code but it is possible that the method may do too much and may need refactoring further than simply providing a more suitable name.

    For a short-term fix, I see nothing wrong with your boss' point of view. In six months when the code needs maintaining, (s)he may think otherwise.

  2. Kim21 בינואר 2009 ב 13:40

    "because it would prevent future bugs"
    Why does you boss think that? Does it make sense to you? (Not from a coding standard point of view, but from a maintenance point of view.
    If the method has surprising side effects that itself could be a reason for future bugs.

  3. shayf21 בינואר 2009 ב 14:05

    @BlackWasp – the GetMMM is a name I made up, the actual method name was GetCustomFields 🙂

    @Kim, I think that this code will prevent bugs in the short run but will cause more bugs (and they will be hard-to-debug ones) in the long run.

    My questions are more general though, I'd like to know what the community thinks about the hypothetical case 🙂

    Thanks for the comments!

  4. Gil Fink21 בינואר 2009 ב 14:33

    Hi Shay,
    A piece of code that prevents bugs and breaks all coding standards while doing so can be in the long run a point of failure in your system. If this piece of code is an atomic operation (like get operation) it shouldn't have any side effects like adding stuff. About the first question, sometimes we need nonrational coding approach to solve problems. So the answer is not always.

  5. BlackWasp22 בינואר 2009 ב 16:28

    GetMMM vs GetCustomFields. Much better, I now know what it does… Except, it writes data too so maybe I don't.