Krista's Coding Corner

18.03.2012

Good code? -naming

Good code works, for starters. But that really isn’t enough. It also has to be clear, elegant and efficient. Witty code that has lots of tricks in it, is one of the worst ones. Coding is not the thing where you show your wittiness and other gimmicks. It makes code hard to understand, debug and develop.

Always remember that anyone can create unclear, hard and messy code (or writing!) but rare are able to do code that others can easily read and understand. Making simple and easily understandable code means skills and brain. There is no excuse NOT to write this kind of code. Either one is not able to do it, is unsecure of one’s job (messy code can be called job security and that is really unprofessional) or….hhmm… no other real reasons really.

So, try your best to be a good coder by creating good code. Next, I’ll introduce some practical features that good code has. I will separate them into a couple of posts as otherwise this would become a really long post… :)

Descriptive naming of variables and functions

Name everything according its function or meaning. If your function checks whether name x is on the table, name it for example as is_name_on_table and not tstfUnc1. Because many editors offer completion, there is no reason to avoid longer, more descriptive names. Same applies to variable names. Think account_balance versus ab. With really good and describable names you need lesser comments.

blog comments powered by Disqus