Home > Articles > Programming > Java

  • Print
  • + Share This
From the author of

Inconsistent Spacing and Indentation

The third giveaway for bad code is the inappropriate use of spaces for indenting the code and separating the program’s elements. There are many different ways for indenting the code to indicate its structure, but there are no excuses for using none of them, for inventing a new one, or for combining two of them in the same file. Any one of those three sins should alert you that the code is sick, and the problems could go deeper than its surface.

The same goes for the use of spaces for forming statements and separating operands from operators in expressions. Novice programmers often fail to notice that there are specific spacing rules for programs. I can still remember an afternoon in 1983: it was only three months after I had started learning C from a third generation photocopy of K&R, and I was anxious to show off my code to a friend who was at the time studying computer engineering. He flatly told me that my code had too few spaces, and didn’t offer a word of praise. You certainly wouldn’t want to maintain the code I was writing then, so watch out for those spaces.

  • + Share This
  • 🔖 Save To Your Account