BattlefyBlogHistoryOpen menu
Close menuHistory

Prettier is brutal, but the future of AI?

Ronald Chen February 28th 2022

Prettier is an opinionated code formatter that intentionally has few options. While prettier will never add/remove code, it will brutally reformat all the whitespace around the code to a fixed style. At times Prettier will reshuffle multiple lines just because a variable name got longer by 1 character.

This seems counterproductive for a code formatter as wouldn’t that mean one could never format the code into their prefered style? Doesn’t this mean prettier would destroy the styling which was maintained to assist in understanding of the code? Yes and yes, but these are good things.

Tabs vs spaces? Doesn’t matter move on

The main value of prettier is its lack of options. This moves all the bikeshedding out of your team and into the prettier project. Your team can focus on delivering value and avoid debating code styling issues in a pull request.

Prettier may be brutal, but brutally consistent

At first prettier will format code into a style which just grinds one’s gears. How can we have any self-respect with code this ugly?

After awhile with constant exposure to prettier, neural adaptation kicks in. One become less triggered by the brutal code styling as they become used to it. In-fact, over time one will come to accept and maybe even prefer prettier.

The nice thing about prettier is there isn’t any opportunity for new code styling to be introduced by a new smelly hire. Prettier smashes everybody’s code into a single style. No training required.

You think that’s ugly code? Check this out

A shift in perspective occurs once code styling is immutable. As one can no longer complain how poorly the code is formatted, one can only point to real issues with the code. Poorly named identifiers and poorly structured code suddenly become more obvious.

But what about the situations where prettier made the code harder to understand? Let’s consider what one is really saying there. Was the code so close to the edge of understandability such that a simple reformatting made it unintelligible? Perhaps we should write code that is more resilient than that. Perhaps we should write code that is simple and robust, such that it survives severe refactorings, let alone reformatting.

But prettier is just wrong in this case! That could be and if prettier has made the code worse for everybody, then one ought to open an issue with prettier. Contribute a better styling for everybody that solves real world problems.

When prettier makes code harder to understand it’s a hint the code is poorly structured. Break down the code to simpler bits with better names and one will realize it wasn’t the fault of prettier the code was hard to understand.

Prettier is no HAL

Everybody has a grand vision on what artificial intelligence will allow us to achieve, but nobody knows how we’re going to get there. While clearly prettier is no AI, I think the way it functions is a glimpse into the future of government by algorithm. Ultimately we just want to be treated fairly and have the ability to influence how society functions.

Prettier is the same in this respect. It forces a single code styling across all code bases and encourages ones to improve code by restructuring. We can all contribute new ideas directly to prettier on how code styling functions equally for everybody. If only future government AI’s are as fair.

Do you want to deliver real value over debating code styling? You’re in luck, Battlefy is hiring.

2024

  • MLBB Custom Lobby Feature
    Stefan Wilson - April 16th 2024

2023

2022

Powered by
BATTLEFY