Turning inner space into outer space

October 27, 2020

Prettier, prettier good

The thing about code is that computers don't care what it looks like. That's why you can get away with "minifying" it into a single grey line that extends to forever.

That doesn't work for the average human being. We have indentations, syntax colouring and a few other tricks to help us better understand what's going on.

What this formatting looks like is a matter of person preference, but certain conventions have become accepted. You could ignore them, but others would silently judge you as either a heretic or a newbie.

People working on the same team sometimes agree on using the same conventions, making it easier to understand one another's code. Because it can be hard to agree, a convention might even be imposed by management.

A neutrality has grown around a plug-in called Prettier that is available for many code editors. It is, as they say, opinionated — meaning that in the vast majority of cases it refuses to give an inch on how it decides code should be formatted.

That means almost zero customization, which was almost a deal breaker for me.

For example, Prettier forces you do use <br /> instead of the more modern <br>. This is meant to be a compromise for people coding XML, where <br /> is required. For HTML, it is recommended.

There are a few other things that grated on me, such as putting paragraph tags on their own line if the paragraph's content goes over one line. Also, it puts classes and attributed within a tag on their own lines if they get to be long.

As with a lot of things in life, if you use something long enough you get used to it. That means when Prettier doesn't work — which can happen if you make an error — the code looks downright ugly.

It makes me wish Prettier were more forgiving of my mistakes.