3 ms·
What we should be able to write in Go, but can't because the compiler (wrongly) imposes formatting: if a { v = 1 } else if b && c { v = 10
by networkimprov 7y ago
What we should be able to write in Go, but can't because the compiler (wrongly) imposes formatting:
if a { v = 1 }
else if b && c { v = 10 }
else if b && !c { v = 100 }
else { v = d }
- atq2119 7y agoNo. This kind of alignment is basically always a mistake and hurts software maintainability in the long run. The problem is that if one of the conditions changes, for example due to a variable renaming, you likely have to change the alignment on all lines. Aside from being very tedious even if you're a lone coder, this creates noise in diffs that makes automatic merges fail much more frequently.
- Cthulhu_ 7y agoI strongly disagree; creative formatting like this means that as a reader, you have to squint and readjust to this new style to see what is going on. I mean, this whole thread reads like a holy war about code style - something the Go developers EXPLICITLY want to avoid because discussions about code style are a waste of time. Everyone reading the above segment of code will have a different opinion on how to format it, while the real question should be "What does this code do". I mean this is highlighted in the preface of the presentation: "When you or I say that a foreign codebase is unreadable, what I think what we really mean is, I don’t understand it." When I read this code I don't understand it, and it's not because of the formatting per se. Playing with the formatting does not make the purpose of the code clearer. This whole thread where people argue about how to best format a structure is missing the point of the article completely.
- GorgeRonde 7y ago> When I read this code I don't understand it ?
- deleted 7y ago[deleted]