Naming things right 26 Apr 2014

Refactor your code!

One of the biggest improvements I’ve made as a programmer has been changing my naming and commenting habits. I used to be a huge fan of commenting everything, and didn’t give naming a second thought.

  • The thing is, you shouldn’t need comments to explain what your code does; if your code doesn’t explain itself, you aren’t doing it right!

Using cool abbreviations and tons of underscores/dashes/other strange things might make you feel like a secret agent, but at the end of the day other people need to understand your code.

Every method and variable name should be understandable either on its own, or knowing only the parent object. Names like Buffer._prepare() are entirely useless. Buffer.clearWith(0) on the other hand, is both intuitive and useful to other classes.

The above example is also one of breaking out private methods and making them reusable. The benefit isn’t only in semantics; cleaner code is maintable code, and reusable code is better code :)