HowTo: Write more comprehensible code

Here are six tips on writing maintainable code; via /.: The tips are

  1. Comment like a smart person;
  2. Use #define a lot; No, a LOT;
  3. Don’t use variable names that will mock you;
  4. Do error checking. You make errors. Yes, you;
  5. “Premature optimization is the root of all evil” — Donald E Knuth; and,
  6. Don’t be too clever by half.

Go to the article for detailed explanations of each tip with sample codes. Have fun!

Advertisements

3 Responses to “HowTo: Write more comprehensible code”

  1. Biswajit Says:

    Not sure about the #defines. I’ve debugged code that had far too many #defines and #ifdefs.

  2. Kodanda Says:

    Dear Guru,
    what about FORTRAN? it is too hard to follow the first 3 😦

  3. Guru Says:

    Dear Biswajit,

    I learnt using #defines and #ifdefs rather late; I did find them useful in making the code more organised, especially, when I wanted to have tests runs which will output lots of stuff and production runs where I wanted the code to be very efficient. Further, as the piece notes, collecting all magic numbers using #define makes debugging easier and the code less bug prone. Of course, the GNU coding standards has some advice too on the issue.

    Kodanda: Are you using a FORTRAN code for your thesis (assuming you are the Kodanda I know–Mangipudi)? I am not sure about the names; however, I think the first two you can still do. But you have to ask Phani–he might know the details.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: