Good code ?

I stumbled upon one of the many coding guidelines at Hacker News this morning. What struck me was that most of them are just common sense.

In summary:
Make it readable

The rest of the article went on to explain “what” is readable and “how” to make it readable.
So, “what” is readable ?
  • Nice layout
  • Clear
  • Short
  • Not ambiguous
  • No surprises
  • etc
“how” to make code readable? Again, common sense (in no particular order):
  • Reduce clutter (comment as necessary, use single-letter variable names when in context)
  • Logical white-spacing
  • Use plain English and make sure it made sense (class and instances as nouns, functions as verbs)
  • Be consistent
The coding guidelines article is still worth a read. There are even books written on the whole topic: Clean Code and Code Complete comes to mind. But reading such article depressed me. Aren’t all this just common sense? Quite often the practice of writing code is treated as distinct and separate from communicating code. This is not true. They are one and the same. IMHO as long as you write code with the courtesy and discipline to make sure other people can understand it, then it will be good code. Not great code…. but you’ll be on the right track.