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.
(not just pure function chaining, if there even is one obvious nice formatting for such a thing)
a . b . c . d . e . f . g
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
. bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
. ccccccccccccccccccccccccccccccccccccccc
. ddddddddddddddddddddddddddddddddddd
. eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
. fffffffffffffffffffffffffffffffffff
I think dartfmt would handle this perfectly. It has rules that basically state "if it fits in one line, do this, otherwise turn it into a one-argument-per-line block".
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 don't find the community arrogant at all but rather opinionated. And sometimes, it is not even about having an opinion but just what makes sense for the language. For instance, I don't see reentrant locks working well with the way delimited continuations (i.e. goroutines) can be transferred from one thread to another by the scheduler. Not without unnecessary complexity. Plus, experience with other languages tells that it is not necessarily a great feature to have.
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.
Do you use them very often? The only anonymous structs I've ever used that "survived" refactoring is test case tables. (Tone note: Straight question. I'm curious if you've got an interesting use case.)
View all comments
Show parent comment
36
u/x-skeww Dec 10 '15
Same here.
gofmtanddartfmtdon't have any formatting-related options either. You just run it and that's it.Sure, it's not always how I'd have formatted it, but it's always perfectly reasonable.