Coding Conventions

Does it take you ages to work out your next line of code? Do you have to repeatedly go back and check on variable and function names? Are you not sure which set of brackets you're currently in? Do you have trouble finding portions of your code?

Chances are that you could do with standardizing your coding habits. Variable names, for example could be more meaningful, var1, var2 and var3 don't mean all that much. Age, height and date, however, tell you a lot more. And maybe you could stop putting underscores in some variables and dashes in others. It's much faster when you don't have to check if you dashed or underscored.

Indenting is another often unconsidered trifle. If you indent every time you enter brackets and outdent (is that a word) when you leave 'em, you'll never have to worry about which brackets you're currently in, again.

Another something you might like to consider is adding an empty line between areas of code. It's creates white space around the code and it's much easier to spot individual areas rather than trying to trawl through pages of code.

If you've got a lot of code, commenting is also useful (and required in collaborative projects). It's takes a bit of effort to tell what someone's code is supposed to do (or your own, if its been a while), especially if its complicated. At a minimum comment your functions, saying what they take in, what they do and what they output. That way, you don't have to know how the function works in order to use it.

So you see, conventions save you time and effort. Now, make up some of your own, is there a way you could make coding easier, if you just did something every time you did something else? Try it, you'll become a better developer for it.

 
08/12/2009