Hacker News new | ask | show | jobs
by peterevans 3036 days ago
A pretty printer, historically—going all the way back to indent—allowed the user to define a bespoke style guide, with a specific indent level, with one way to align braces, etc. You could implement GNU-style C code with indent; you could implement Allman-style C code; you could mix in your own preference for indent level.

As such, I think your complaints are misplaced. gofmt is not a pretty printer. It's designed to implement a single standard format—one which does not define a maximum line width—but nothing more.

1 comments

The purpose of a pretty printer is to increase readability of code. (This isn't controversial.) One of the most important aspects of code readability is line length. By not addressing that, gofmt isn't fully solving the problem that pretty printers are designed to solve.

Indent, by the way, allows for a maximum line length.

As I said: gofmt is not a pretty printer.

It may help if you decouple the goal (increased readability of code) and the action (application of a style to code). Pretty printers—and gofmt—apply a style to code. That is their only job; in a traditional pretty printer, you could configure a terrifyingly awful style of code, and it would apply it happily and correctly. The readability of that style is a subjective judgment to others, but this is in no way a concern of the pretty printer.

You may not like the style of code that Go uses. That is a perfectly valid viewpoint, and I encourage you to develop it as you see fit! It is also perfectly valid to criticize the style choice of having an undefined maximum line width.

The problem gofmt solves is not "how do we allow you to style Go code", but more specifically, the problem it solves is "how do we encourage the community to adhere to one style of code for Go?" And it is successful in that. It is obviously unsuccessful in applying a style that you find aesthetically pleasing—alas!

Also, I am afraid that I did not claim indent does not allow for a maximum line width! I said that indent (like other pretty printers) allowed you to define a style "with a specific indent level" and that "you could mix in your own preference for indent level".

> The problem gofmt solves is not "how do we allow you to style Go code", but more specifically, the problem it solves is "how do we encourage the community to adhere to one style of code for Go?" And it is successful in that. It is obviously unsuccessful in applying a style that you find aesthetically pleasing—alas!

It's not successful if everyone puts line breaks in different places. By punting on that problem, gofmt isn't enforcing one style of code.

gofmt did not intend to solve the problem that pretty printers are designed to solve, but rather to unify formatting to remove formatting contention within the ecosystem.

A typical pretty printer has knobs and dials to control its output, for instance — gofmt has none.