topic: Use an autoformatter

Readability counts

“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live” - John Woods

Code is read more often than it is written. Therefore it is efficient to make your code easy to read.

You need to consider the next developer who will deal with your code as your client. If you write unreadable code you have let your client down.

Formatting your own code by hand is a waste of your time

Making sure that your code is consistently formatted is important, but doing it all by hand is boring and prone to human error.

People shouldn’t need to waste time formatting code by hand. A machine can do a much better job. You can spot if a person is doing it by hand if:

  • their code is hard to read because it’s squished or inconsistent
  • they have tab characters in their code

All modern code editors worth their salt allow for some kind of autoformatting.

  • In Python we use the black autoformatter
  • In JavaScript we use the default Prettier settings

Suggested action

Get the learner to set up their code editor properly. If they use vscode then they can set it up so that the formatter gets triggered every time they save a file. When you use the right tool for the job then everything is just better.


RAW CONTENT URL