Call Us: US - +1 845 478 5244 | UK - +44 20 7193 7850 | AUS - +61 2 8005 4826

The Psychology of Computer Programming,

Underestimating the Importance of Code Quality

If you can only focus on one aspect of the code that you write, it should be its readability. Unclear code is trash. It is not even recyclable.

Never underestimate the importance of code quality. Look at coding as a way to communicate implementations. Your main job as a coder is to clearly communicate the implementations of any solutions that you are working on.

One of my favorite quotes about programming is:

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

— John Woods

Brilliant advice, John!

Even the small things matter. For example, if you are not consistent with your indentation and capitalization, you should simply lose your license to code.

tHIS is
  WAY MORE important
            you think

Another simple thing is the use of long lines. Anything beyond 80 characters is much harder to read. You might be tempted to place some long condition on the same line to keep an if-statement block more visible. Do not do that. Just never go beyond the 80 character limit, ever.

Many of the simple problems like these can be easily fixed with linting and formatting tools. In JavaScript, we have two excellent tools that work perfectly together: ESLint and Prettier. Do yourself a favor and always use them.

Here are a few more mistakes related to code quality:

  • Using many lines in a function or a file. You should always break long code into smaller chunks that can be tested and managed separately.Any function that has more than 10 lines is just too long.
  • Using double negatives. Please do not not not do that.Using double negatives is just very not not wrong.
  • Using short, generic, or type-based variable names. Give your variables descriptive and non-ambiguous names.There are only two hard things in Computer Science: cache invalidation and naming things.— Phil Karlton
  • Hard-coding primitive strings and numbers without descriptions. If you want to write logic that depends on a primitive string or number, put that value in a constant and give it a good name.const answerToLifeTheUniverseAndEverething = 42;
  • Using sloppy shortcuts and workarounds to avoid spending more time around simple problems. Do not dance around problems. Face your realities.
  • Thinking that longer code is better. Shorter code is better in most cases. Only write longer versions if they make the code more readable. For example, do not use clever one-liners and nested ternary expressions just to keep the code shorter, but also do not intentionally make the code longer when it does not need to be. Deleting unnecessary code is the best thing you can do in any program.Measuring programming progress by lines of code is like measuring aircraft building progress by weight.— Bill Gates
  • The excessive use of conditional logic. Most of what you think needs conditional logic can be accomplished without it. Consider all the alternatives and pick exclusively based on readability. Do not optimize for performance unless you can measure. Related: avoid yoda conditions and assignments within conditionals.