5 ms·
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 subjectiv
by hardwaregeek 3y ago
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 good. And even then I anticipate more than a few comments decrying prettier’s formatting. You can’t please everybody. That’s why it’s prettier not prettiest
- chubot 3y agoI think I agree about the testing and labor of complicated translation rules. But it doesn't appear that almost every pretty printer is based on the Wadler algorithm. It seems like MOST of them are not? e.g. clang-format is one of the biggest and best, and it has a model that includes "unwrapped lines", a "layouter", a line break cost function, exhaustive search with memoization, and Dijikstra's algorithm: https://llvm.org/devmtg/2013-04/jasper-slides.pdf https://llvm.org/devmtg/2013-04/jasper-slides.pdf The YAPF Python formatter is based on this same algorithm - https://github.com/google/yapf https://github.com/google/yapf The Dart formatter used a model of "chunks, rules, and spans" - https://journal.stuffwithstuff.com/2015/09/08/the-hardest-program-ive-ever-written/ https://journal.stuffwithstuff.com/2015/09/08/the-hardest-pr... It almost seems like there are 2 camps -- the functional algorithms for functional/expression-based languages, and other algorithms for more statement-based languages. Though I guess Prettier/JavaScript falls on the functional side. I just ran across this paper that includes a nice survey (on lobste.rs) and it seems to cover the functional pretty printing languages influenced by Wadler, in the functional style (e.g. for and in Racket or Haskell), but not the other kind of formatter ("Google" formatters perhaps) https://arxiv.org/pdf/2310.01530.pdf https://arxiv.org/pdf/2310.01530.pdf
- hardwaregeek 3y agoAh that’s a good point. The Dart one is the Wadler one with modified terminology, but the rest do appear to be different
- reactordev 3y ago>”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 https://www.npmjs.com/package/prettiest
- throwup238 3y agoDropping the R would still make the name quite apropos for a formatter. The pettiest defaults.