HN Hall of Fame Weekly email

The Hardest Program I've Ever Written – How a code formatter works (2015)

journal.stuffwithstuff.com Essays & writing Essays & articles Software engineering Class of 2019-11 Hall of Fame
Screenshot of journal.stuffwithstuff.com captured 2026-07-20
Page preview · captured 2026-07-20

The originally submitted URL now redirects to the address above. Updating the destination does not change the item’s HN history, Hall membership, or rank.

Submission timeline

2007–2026

One slot for every year since HN launched. Height is that year's peak points; orange marks a 100+ point or 50+ comment breakout. Select a bar to open its strongest thread.

Top comments

HN comment order

Philip Wadler has a seminal paper [0] on implementing pretty printers by modeling them using an algebra. There's implementations of the algorithm in most programming languages nowadays, and some state of the art advances that help with performance [1] It's a very elegant algorithm, and is very pleasant to work. Elixir's formatter uses a variant of it [2], and it appears in the standard library [3]. I've personally made use of it to write a code formatter for GraphQL queries…

I read this before working on prettier and it was a bit scary to be honest :) I wasn’t convinced that the exhaustive approach with weigths was a good idea. It makes it computationally super intensive and hard to predict what the printer would do. Instead prettier runs on a simple idea: if something doesn’t fit in one line, break the outermost parent. This simple rule (implemented via the Wadler IR) is efficient to implement and makes the output generally…

vjeux·303-point thread·

The Dart formatter sounds really advanced, and reflects potential complexity of the language. I think I'd still prefer to see a formatter attempt to preserve any formatting which is already 'good enough' to pass as an output threshold. Code isn't just a recipe for a computer to do something, it's a language for explaining to other programmers what that thing is and what's important to the structure of accomplishing it. The choice of where to place a break can matter…

mjevans·261-point thread·

Great blog post and super interesting. My feeling though is the problem is they have a line limit. Maybe they should rethink their style. I'm serious. Before I worked at Google, in 30 years of programming I never worked at a company that had a line limit. Adding a line limit at Google did not make me more productive. At first I thought "hey, I guess 80 chars makes side by side comparison easier" but then I thought back, hmm…

The first top-level comment from each of the four biggest threads, in HN’s own order. Excerpts are shortened; open a comment for full context.

HN stats

Breakout years
5

100+ points or 50+ comments

Total points
1416

reference only — not used in Hall rules or ranking

Total comments
472

reference only — not used in Hall rules or ranking

Every submission