Slashdot Mirror


How to Keep Your Code From Destroying You

An anonymous reader writes "IBM DeveloperWorks has a few quick tips on how to write maintainable code that won't leech your most valuable resource — time. These six tips on how to write maintainable code are guaranteed to save you time and frustration: one minute spent writing comments can save you an hour of anguish. Bad code gets written all the time. But it doesn't have to be that way. Its time to ask yourself if its time for you to convert to the clean code religion."

2 of 486 comments (clear)

  1. Re:That was just terrible... by Sax+Maniac · · Score: 4, Interesting
    Right, I laughed at that #define remark, it's so green.

    The real thing is to used named constants where it makes sense. #define is the crudest approximation of that, C can use enums, C++ can use "const" for compile-time values, etc.

    In a real project, you have to scope your constants otherwise you'll have a billion of them in "everything.h" and every time you touch it, the world will rebuild. So nix the "centrally located" file theory.

    In a real project, your constants will often have interdepedencies on other bits of code, so changing one will frequently affect the others. Heck, maybe changing one will cause it not to compile. This example makes them all trivial to the point of uselessness. Shuttling it off miles away in an #include file, can frequently give the impression this than can be changed with no effect on anything else.

    --
    I can explanate how to administrate your network. You must configurate and segmentate it, so it can computate.
  2. Re:Who wrote that article? by Enselic · · Score: 4, Interesting

    I wonder what mushrooms he were on when he came up with that coding style... (yes, this is the actual indentation he used):

    Void change_score(short num_points)
    {
        if (num_points < 0)
    {
    // maybe some error message
            return;
    }

        score += num_points;

        if (num_points > 0)
    make_sparkles_on_score();
    }