7 ms·
Autoformatting is so nice. Crazy to think that formatters only became popular after `gofmt`. I also found this related quote from Russ Cox intriguing: "Most pe
by wonger_ 2y ago
Autoformatting is so nice. Crazy to think that formatters only became popular after `gofmt`.
I also found this related quote from Russ Cox intriguing: "Most people think that we format Go code with gofmt to make code look nicer or to end debates among team members about program layout. But the most important reason for gofmt is that if an algorithm defines how Go source code is formatted, then programs, like goimports or gorename or go fix, can edit the source code more easily, without introducing spurious formatting changes when writing the code back. This helps you maintain code over time."
- DangitBobby 2y agoThat doesn't really seem like a good reason. They remove all formatting control with an automated tool so it doesn't matter when (if, big if) an automated tool later rewrites some of your source code formatted in a way you don't control?
- Nzen 2y agoMu. Russ Cox quote indicates that the maintainers of goimports and gorename do not need to handle formatting at all (and hence, benefit). The go team put that wholly in the gofmt team's court. Otherwise, the go team would likely have to handle tickets about how the formatting of goimports and gorename differ over time for edge cases (if only by paying the social capital of ignoring the tickets).
- DangitBobby 2y agoThat would fall under what I already assumed to be true, and also under an umbrella they specifically said it wasnt about > end debates among team members about program layout (Except in this case of course it's not "team members") I'm definitely not getting this interpretation from the quote.
- striking 2y agoIt's more common than you think! Tools like https://github.com/facebook/jscodeshift https://github.com/facebook/jscodeshift, https://ts-morph.com/ https://ts-morph.com/, and https://ast-grep.github.io/ https://ast-grep.github.io/ are the ones I'm more familiar with (since my day-to-day is TypeScript). When I led the conversion of a decently-sized codebase from Flow-typed JS to TypeScript, I ensured that a code formatting tool that we were already using on pre-commit and CI called `prettier` was executed after each step. We took a git snapshot of each step of our automated conversion pipeline, and the diff was much clearer with `prettier` in place at each of those steps. We've since used codemods frequently to make huge changes to the codebase in an automatic, reproducible, iterable way. They're very comfortable, very fun, and (thanks to the use of a formatter on all code) rarely produce incomprehensible diffs.
- delichon 2y agoIt reduces cognitive load on integrations, both software and wetware. So many brain hertz are wasted on internally bikeshedding format details. Autoformat fixes a hole where the rain gets in and stops my mind from coding.
- autarch 2y agoThe Perl world had perltidy (first release in 2002) many years before Go was even a thing. It's funny that Perl, a language notorious for it's "There's More Than One Way To Do It" (TMTOWTDI) philosophy had a tidier so early. Of course, perltidy is _ridiculously_ configurable. One thing I really love about gofmt is that it has no configuration at all. I think that was a major "innovation" and I'd love to see more languages adopt this approach.
- XorNot 2y agoThere were also various Python formatters. The problem was the zeitgeist - engineers would tell me that "they didn't want an algorithm messing with their code" as though that was a serious concern, or that wading through endless pull-request changes for syntax was a good use of anyones time.
- ravishi 2y agoThe thing about configurable vs non-configurable in this case is that when its configurable then people will spend time debating how exactly they should configure it.
- autarch 2y agoYes, that's why I love gofmt. There's nothing to debate!
- jrockway 2y agoHelpfully, you can debate between "gofmt", "gofmt -s" and "gofumpt". I actually like how gofumpt formats stuff but ... nobody else on the team would have it, so it would make things worse.
- autarch 2y agoYeah, there's still a few options. But try running `perltidy --help`. Even that doesn't really give you a sense of how many options there are because many of the options are not booleans, but instead take several enum values indicating which style to choose.
- afavour 2y agoI’ve wondered before whether the world would be well served by a programming language (or source control system, I suppose) that just stores ASTs in files rather than text code. When users open the file the editor formats to whatever their personal preference is, then saves edits back to the AST. It really is dumb to be arguing over tabs vs spaces, after all.
- rsc 2y agoAt that point you could even use different languages. Maybe you like programs that look like Lisp and I don't. There was a project at Microsoft Research in the late 1990s/early 2000s that did exactly this - storing ASTs in source control instead of code - but the name escapes me at the moment.
- whstl 2y agoWas it Intentional programming? I remember it being described as something similar to what you say, but the Wikipedia shows something slightly different. https://en.wikipedia.org/wiki/Intentional_programming https://en.wikipedia.org/wiki/Intentional_programming
- refulgentis 2y agoQuick 10 min into Googling, def. double check me: You're right, ex. https://dev.to/jillesvangurp/comment/6gnb/ https://dev.to/jillesvangurp/comment/6gnb/ Sadly there's enough bitrot that ex. intentsoft.com is offline. More here, but article is v opinionated/judgement oriented, comments are useful, but again, bitrot :( https://wiki.c2.com/?IntentionalProgramming https://wiki.c2.com/?IntentionalProgramming It strikes me that what I am describing as "bitrot" may also be "never really shipped, so the vagueness isn't accidental"
- throwaway2037 2y agoHat tip for c2.com link! The follow-up is savage: https://wiki.c2.com/?CritiqueOfIntentionalProgramming https://wiki.c2.com/?CritiqueOfIntentionalProgramming
- omoikane 2y agoAutoformatters got popular was because a lot people don't care about formatting, and those who do care can't win against the auto part of autoformatters. It works for go because gofmt was there from the start, so even if you are returning a multi-dimension array and elements come out unaligned, that's just accepted as how it is and nobody cares. For other languages, people will have to either accept "not caring" as becoming the norm, or actively fight the autoformatter from steamrolling over their code. For people who would give more thought to how their code would be read, autoformatters were often more frustrating than "nice".
- YZF 2y agoInteresting enough people still find things to argue about even with gofmt and goimports. The order of imports and maximum line length are two examples. I imagine if those were done by gofmt/goimports then people would argue about other things. It's why we can't have nice things... Autoformatters do help though.
- freedomben 2y agoYes precisely this. I worked on a team in C++ that vertically aligned things, and at first it seemed like extra work but once I started seriously reading the code, I had an epiphany of realization that it is an amazing improvement in readability, but also makes it super easy to find certain bugs, and also do block editing in tools like vim. After leaving that team, I found that everywhere I tried to introduce this people just shrugged and rolled an auto-formatter over and told me that it's not worth thinking about. IMHO autoformatters are awesome until there's something you care about that the implementers didn't care about, then they are horrible. Problem is, the people who put a lot of thought into those decisions are often in the minority and tend to lose the argument.
- rowanG077 2y agoI never thought it only got popular with go. I remember using formatters before go. What go did do is that it shows how good it is if it is ubiquitous.
- plorkyeran 2y agoI think mandatory code formatting was popularized by Go? Plenty of code formatting tools had been around for quite a while by the time Go came out, but they were the sort of thing you ran on a codebase once to clean up a mess, not something you checked on each commit. A common sentiment was that it was a good idea but was only viable because Go had it from the beginning, which fortunately turned out to be wrong.
- fweimer 2y agoJava IDEs have had optional reformat on safe for a long time. https://help.eclipse.org/latest/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fpreferences%2Fjava%2Feditor%2Fref-preferences-save-actions.htm https://help.eclipse.org/latest/index.jsp?topic=%2Forg.eclip...
- jakjak123 2y agoThey have, but the different IDEs do not format equivalent and are way too easy to reconfigure to personal preference.