I couldn't imagine myself returning to languages with exceptions and ternary operators, for example.
Why ? Is it because no language with those feature is good (let say you wouldn't like to return to Java for instance), or is it because you genuinely prefer this over ternary operator :
if expr {
n = trueVal
} else {
n = falseVal
}I know that the typical answer is "it's just bad programmer", but that's where Go chooses different view. Many design decisions in Go were taken with awareness of the social context of programming.
If the feature incentivizes using it in a wrong way - it's not a bad programmer, it's a bad feature. Programming language is a language between humans in a first place and it should be readable as much as possible, it should deincentivize using obscure and easy-to-use-improperly things.
It so much better when you go to practically any Go repository and find that code is readable and clear. I've never had this experience with any other language before.
PS. Found one of the real examples of abusing ternary operators. That was one of the coolest I've seen. And I guess it's easy to understand that the same programmer wouldn't write the same with "if .. else .." blocks in Go. He would realize that it's too verbose and hard, hence probably wrong design, so he need to find better solution within the space of language features. http://imgur.com/a/hjKOe
What languages did you have to endure before?
> Found one of the real examples of abusing ternary operators.
Yeah, the original code is silly, the binary search trees are not always balanced. They should be more like:
if (type <= 10) ? (if (type <= 5) ? ... : ...) : if (type <= 7) ? ... : ...So there's nothing good about alcohol (it may cause liver damage), cars (they may cause accidents), prescribed drugs (they may have unpleasant collateral effects), ...
Hey, it's also true that programming incentivizes bugs, so programming is bad. Let's stop programming!
var n int
if expr {
n = trueVal
} else {
n = falseVal
} n := map[bool]func() int{
false: func() int { return falseExpr },
true: func() int { return trueExpr },
}[expr]()
https://play.golang.org/p/TXIse32WD9Now, let's see how to abstract it with "go generate"...
n := defaultVal
if expr {
n := otherVal
}
Which I think is easier to understand, and not that much more typing. YMMV of course. n = if expr trueVal else falseVal
(which is what e.g. Scala does) over meaningless-unless-memorized '?' and ':'Reminds me of Rob Pike's post: https://commandcenter.blogspot.fr/2011/12/esmereldas-imagina...
Reading, maintaining and improving legacy codebases are some of the hardest.
If that extra typing makes it much easier to do the above tasks, I don't mind doing this.
Go runtime panics include stack traces, complete with the offending statement's line number in the source code.