Advice to budding programmers: Write neat code

What exactly do I mean by neat code? We all write code on the computer with a keyboard isn't it? How can code be neat or not neat when you do that!?

Well, let me explain. Take a look at this:








Now, compare that with this:
















Exactly the same code. But just look at the difference. All due to some simple formatting. Makes everyone's life so much easier. The programmer's too.

I am not even talking about coding conventions like method and variable names and all that jazz. Just the style of writing code. Some simple rules. Here are a few to get you started:

1. Leave the rest of the line after an opening brace empty
2. Leave a single blank space before and after any operator (=, +, - etc.)
3. Leave a blank line after a related group of statements
4. Indent one level for every block of code. For example, everything inside the for block should be indented one level more than the for statement itself.

Such simple rules go a long way in making code more readable, maintainable and easy to debug.

During my career in the software industry, I have seen the code of two people which are inspirations to me in this aspect - Shanivarapu Ram Seshu Kiran - S R S Kiran in short and Abhilesh Khatri. Both of them worked with me in Effigent. Their code was a pleasure to review. Everything would be so neat. So well written. And they were good technically too.

Another person who has been a guiding light in this respect was Suresh Pai - again ex-Effigent. Suresh was very particular about the way people wrote code. He insisted that everyone followed rules similar to the above.

Some people might argue that these kinds of things are trivial and not important while writing code. I would strongly disagree. Readability and maintainability of the code are extremely important. The author of the code is not always available to maintain his code. And even if he is the one maintaining it, neatly written code is much easier to manage.

(The bad alignment of the text above is a bug in Blogger. The Preview shows it properly.)

Comments