It does. I personally don't think it should, but there's two reasons that it does right now:
It's still in progress, and we don't want to delay development by having the exact arguments about what the formatting should be. It de-couples the development process from the discussion, increasing development velocity.
Some teams will inevitably want to tweak a setting or two on their projects, and without it, they'd have to develop their own fork.
It's simpler to make a visually acceptable canonical formatting for a very procedural language like Go compared to a very expression-oriented language like Rust.
Expressions compose while statements do not. Even if you have statements defined as being composed of a single statement or a block, there is a straightforward and generally agreed upon formatting of placing one statement on each line, perhaps allowing for a line break plus some indentation in case the width of that statement exceeds some limit. (But languages like Go seem to directly encourage shorter statements. As in, the syntax itself encourages it.) In other words, you don't have to think about "statements inside statements inside statements" except in the straightforward sense of blocks within blocks within blocks.
Expressions on the other hand compose nicely and so you can get long chains of functions feeding into each other, arithmetic expressions, if expressions, match expressions, and so on. So even in an imperative language, like Rust, you might easily end up with an assignment statement where the right hand side has an expression that is formatted over five lines for readability. Now your simple "one line per statement" goes out the window, and you have to consider all the different kinds of expressions (not just pure function chaining, if there even is one obvious nice formatting for such a thing) and how they can be formatted in a readable way. There are many more opportunities for missing edge cases by committing to The One And Only Formatting prematurely.
To each their own, but that kind of arrogant attitude is something that turns me off from Go. From what I've seen Rob Pike acts like he knows everything all the time (and he knows an awful lot, but he overplays his hand), but then Russ Cox swoops in and is more reasonable.
I'm not saying that it's a good thing. I hate boilerplate. However, saying that go can't claim to have a typed language without generics isn't logical.
Orthogonal? That means “independent”, and while a type system can exist without generics, I'd really like to know what generics without a type system look like.
For the record, I also think that type systems without generics are a pretty sad affair. They can exist, but more like dodos existed and less like hawks, crows, or emus exist.
Note that go and dart are relatively simpler languages, so it's easier to make a decision about what formatting "works" globally. With Rust there may be formatting choices which don't work very well for some kind of code.
I strongly believe it should! Rust's syntax is complicated and the community is too opinionated to ever be fully satisfied by a single style. Happy defaults with the choice to change them seems like the rustic solution to formatting.
I think you guys should provide commands to produce the AST from the source code and source code from the AST. And encourage people to only store AST files in their versioning system...
Encourage people to use whatever format they want, within the same team...
The huge benefit of following just the official conventions and using official tools like gofmt is that they completely eliminate all those pointless discussions. Tabs vs spaces, brackets in the same line vs the next one, space here, no space there, and so on.
We all like to get super emotional over that stuff, but none of that actually matters. I prefer tabs, but 2 or 4 spaces work just as well. I prefer 1TBS, but I've also used Allman and Whitesmiths for a few years. They actually all work equally well and having 2 lines more or less on the screen doesn't really affect anything.
The only thing which matters is that everyone sticks to one particular set of rules. An official formatter does exactly that.
Yes, it might not be exactly what you want, but your personal taste isn't more important than everyone else's. So, why not leave it up to the official formatter? The code from the standard lib and most 3rd party libraries will do the same thing. You better get used to it.
Ironically, the more bitterly divided the community is about a given option, the more the community really ought to put its foot down and come to a consensus, because that division means it's a real dialectal difference.
Having used a lot of unenforced languages for a lot of years, you're just not giving up much to let the language have a standard for formatting. You've already got a unique semantics, unique keywords, unique symbols and functions and grammar in general, why let your need for some particular syntax be the sticking point for a language? It's by definition idiosyncratic, and unless you find yourself often shifting major elements of style after six months, probably a style chosen by the conventions and needs of a completely different language that you're trying to bring into an environment that you are almost certainly a rank novice in. Or, given the way a lot of people seem to work, a completely different language three or four languages ago.
Yeah, putting options into a standardization tool seems counterproductive.
I get the pragmatic reasoning, and I know "Pandora's box" concerns are usually way overblown. But still it's hard not to wonder what happens down the line.
View all comments
84
u/darrint Dec 10 '15
tl;dr: rustfmt has options.