Live data from Hacker News

Why is Prettier rock solid?

mrmr.io

11–20 of 163 posts

Re: Why is Prettier rock solid?

#11

I'm not sure I got an answer to the question in the title. Prettier is rock solid because it was based on a paper by someone who designed Haskell? That's a cool link, but I'm not sure what the insight is, is this evidence that functional programming-style algorithms lead to a more stable codebase?

I think prettier's initial author answered the question quite concisely in the article's first link. Title and excerpt copied below:

> Dig into past research.

> If you're excited about an idea, it's super tempting to sit down an immediately get going. But you shouldn't do that until you've done some cursory research about how people have solved it before. Spending a few days researching the topic always completely changes how I am going to solve it.

https://archive.jlongster.com/How-I-Became-Better-Programmer

Re: Why is Prettier rock solid?

#12

Prettier isn’t terrible but compared to ocamlformat it is soooo… slow. Each time I save it takes a second or two for it to format. Ocamlformat is instant in the meanwhile.

How large are the files you're formatting? I have prettier set to format on save in vscode and even for the largest files in my codebase (>1000 lines) it formats near-instantaneously on my 2019 macbook pro. Definitely well under a second.

Re: Why is Prettier rock solid?

#13

Ehh I would disagree here. Yes, prettier uses the classic pretty printing paper, but almost every pretty printer does in some form. And even then it’s subjective how you compile the actual syntax down to the printer elements. Prettier uses a very thick layer of complicated translation rules to get the printing just right. Especially with JSX and TypeScript. It’s honestly just good old testing and labor that makes it…

>”That’s why it’s prettier and not prettiest” Missed opportunity I think to have a prettier with the prettiest defaults. Sadly the name is taken [0] [0] https://www.npmjs.com/package/prettiest

Dropping the R would still make the name quite apropos for a formatter. The pettiest defaults.

Re: Why is Prettier rock solid?

#14
post #9

This isn’t actually true. Prettier does break code in strange circumstances and it can be very difficult to fix. The maintainers have a ton of stress on them and it’s hard to improve it sometimes. It’s very well tested and easy to add cases too - just add an input and an output so that may be why it seems so solid, just whenever there is an issue people fix it. I think the main thing is that Meta maintains it which p…

What’s an example of Prettier breaking code?

Re: Why is Prettier rock solid?

#15

Prettier isn’t terrible but compared to ocamlformat it is soooo… slow. Each time I save it takes a second or two for it to format. Ocamlformat is instant in the meanwhile.

Take a look at Biome formatter and linter. Blink of an eye fast on very large projects that prettier feels like forever on.

Just don't enable the experimental or potentially breaking format options on a large existing code base. They aren't enabled by default.

Deno's in the box trolling is pretty nice as well. YMMV of course.

Re: Why is Prettier rock solid?

#16
post #2

> note that gofmt doesn't indent, which is the hard part Huh? I'm pretty sure it indents with tabs.

I suspect the author meant that gofmt doesn’t break lines, which dramatically simplifies the complexity. See https://journal.stuffwithstuff.com/2015/09/08/the-hardest-pr... for a fun, related read.

Re: Why is Prettier rock solid?

#17

Prettier isn’t terrible but compared to ocamlformat it is soooo… slow. Each time I save it takes a second or two for it to format. Ocamlformat is instant in the meanwhile.

Take a look at Biome formatter and linter. Blink of an eye fast on very large projects that prettier feels like forever on. Just don't enable the experimental or potentially breaking format options on a large existing code base. They aren't enabled by default. Deno's in the box trolling is pretty nice as well. YMMV of course.

I migrated to Biomejs formatting and never looked back.

Re: Why is Prettier rock solid?

#18
post #9

This isn’t actually true. Prettier does break code in strange circumstances and it can be very difficult to fix. The maintainers have a ton of stress on them and it’s hard to improve it sometimes. It’s very well tested and easy to add cases too - just add an input and an output so that may be why it seems so solid, just whenever there is an issue people fix it. I think the main thing is that Meta maintains it which p…

What’s an example of Prettier breaking code?

The biggest issue I run in to is with Django HTML. It's unusable. They know about it and they said they won't fix it.

Re: Why is Prettier rock solid?

#19
post #9

This isn’t actually true. Prettier does break code in strange circumstances and it can be very difficult to fix. The maintainers have a ton of stress on them and it’s hard to improve it sometimes. It’s very well tested and easy to add cases too - just add an input and an output so that may be why it seems so solid, just whenever there is an issue people fix it. I think the main thing is that Meta maintains it which p…

What’s an example of Prettier breaking code?

For example, the latest Prettier makes XHTML files invalid by changing DOCTYPE to lowercase:

https://github.com/prettier/prettier/issues/15476

Prettier moves ts-ignore comments which can cause TypeScript errors:

https://github.com/prettier/prettier/issues/15876

Interpreting nested CSS functions' "-" as minus and inserting a space:

https://github.com/prettier/prettier/issues/15369

Re: Why is Prettier rock solid?

#20
post #9

This isn’t actually true. Prettier does break code in strange circumstances and it can be very difficult to fix. The maintainers have a ton of stress on them and it’s hard to improve it sometimes. It’s very well tested and easy to add cases too - just add an input and an output so that may be why it seems so solid, just whenever there is an issue people fix it. I think the main thing is that Meta maintains it which p…

What’s an example of Prettier breaking code?

I don’t want to post a specific issue without doxxing myself but you can browse through the open issues on GitHub to find some.

Some are years old! I think the more popular languages tend to be better supported so you probably don’t know about it but prettier is a massive monolith with support for many languages and use cases. Sometimes there are bugs that mangle code

Post reply on HN