4 ms·
> Rob Pike gave a talk last year at the Go Sydney meetup where he talked about the Go 2 changes. In his talk, he suggested that the use of if err != nil in code
by munificent 7y ago
> Rob Pike gave a talk last year at the Go Sydney meetup where he talked about the Go 2 changes. In his talk, he suggested that the use of if err != nil in code bases is nowhere near as common as the vocal minority suggest.
This page shows the most common words found in a large corpus of open source Go code on GitHub:
https://anvaka.github.io/common-words/#?lang=go https://anvaka.github.io/common-words/#?lang=go
The top four most common words are "err", "if", "return", "nil".
These are each more common than "func" and "string" combined. It's hard to square Pike's comment with that evidence.
I don't know if the try proposal is a good one or not, but I think it's pretty clear that Go's original approach to error handling is quite verbose. Whether it should be that verbose is an interesting question, but personally I think making the user repeat that exact same boilerplate every time adds little value. If you want code that can fail to be visible, at least make the boilerplate shorter, which I guess the "try" proposal accomplishes.
- skybrian 7y agoThese words are commonly used individually, but that says nothing about how often they appear in a particular order.
- blondin 7y agohave you tried clicking on that link?
- enneff 7y ago> The top four most common words are "err", "if", "return", "nil". These are each more common than "func" and "string" combined. It's hard to square Pike's comment with that evidence. Each of those words are extremely common in Go code, even outside of the 'if err != nil { return err }` construct. It makes sense they'd be more common than 'func' and 'string' because functions usually contain at least one if statement and return statement, and err is probably the most common variable name, and nil is used to represent the zero value of many different types. The 'string' word is only really used in struct fields, function signatures, and some variable declarations, but usually the string type is inferred on assignment.
- rat9988 7y agoI feel like what you say is tangential. Op didn't say that it isn't logical to see them as most used words. He says that pike's opinion doesn't seem to hold a lot in the light of this evidence.
- liveoneggs 7y agoyou can click on the words and `if err != nil {` is the most common pattern in each with `return err` being second place (both by a large margin) Rob Pike is, very likely, using a different set of programs to judge.
- apta 7y agoJust goes to show how out of touch with established programming language research and practice the golang authors are. Now they're re-inventing exceptions, but badly. It seems a lot of things in golang were done just for the sake of being different, with nothing to back it up.
- hu3 7y agoNot only is your belittling of Go authors gratuitously offensive but it is uninformed as well. That is just one of the many proposals that Go received along the years and there's no intent to implement it at the moment.
- AnimalMuppet 7y agoI'd say it's uninformed for a completely different reason. Look at the bios of the Go authors. "Out of touch with established programming language research"? Seriously? "Making different choices than you would have" != "out of touch with research" - especially when they know the research better than you do!
- apta 7y ago> Look at the bios of the Go authors. Appeal to authority fallacy. Furthermore, this was evident several times when discussions about things like generics came up. I think they even admitted it at some point.
- AnimalMuppet 7y ago> Just goes to show how out of touch with established programming language research and practice the golang authors are. When you said that, was also the appeal to authority fallacy.
- apta 7y agoWhich authority? I observed other languages like Kotlin, Scala, Rust, D, C#, Java, C++ and saw what they have in terms of program design and features.
- adamhepner 7y agoUnrelated, but why on earth is "iNdEx" used almost a million times? Is there a joke that I'm missing at play here?
- tcard 7y agoIt seems it's generated by the protoc compiler. E. g. https://github.com/weaveworks/common/blob/80ff0769bb38e575cd85a64a4575a2ca1ef5ada5/httpgrpc/httpgrpc.pb.go#L671 https://github.com/weaveworks/common/blob/80ff0769bb38e575cd...
- NikkiA 7y agoIt's funny but this reminds me that my first 'wtf C, you are dumb' moment was trying to use a variable name 'index' in some code in 1989, and getting completely incomprehensible errors in return.
- marcus_holmes 7y agoGo's approach to a lot of things is quite verbose. Every editor has snippets, or the equivalent, making boilerplate simple to write. And you adapt to reading it pretty quickly - it just becomes punctuation after a while, and you only notice it if it does something unusual. which is my problem with "try", and why I won't be using it if it gets accepted. It breaks the rhythm of "do something, check for errors, do something, check for errors" that Go code has, and that becomes easy to read.
- PaulRobinson 7y agoOften when we talk about verbosity in a language, we mean something is needlessly descriptive in a way that can make things tedious or hard to maintain. Just yesterday I made the joke that you can recognise a Java developer at a party because they start almost every sentence with "public static void". Ha. See, funny? Go's verbosity feels different, and I don't think it's "verbose". It's clear. It's about making it really clear what is happening. What surprises me about the proposal is that they think that go's error handling does not reduce the number of errors, because in my experience it does in fact reduce the incidence of run-time errors significantly, and also makes it very clear how to maintain error handling code. I'm not sure I like the try proposal, but I'm not sure I hate it. What I do know is that the verbosity you're complaining about doesn't feel to me like the same kind of verbosity I complain about in other languages, somehow.
- keypusher 7y ago> It's about making it really clear what is happening. You could say the same thing about Java, so your argument basically boils down into “I like Go, and I don’t like Java”. What is clear and important to one person is needlessly verbose to another, what is cryptic to a newcomer might be beautiful and concise to an expert. I’ve encountered idioms that horrified me the first time I saw them which I eventually grew to love, and I’ve been smitten by syntax sugar that I thought would be great and turned out to be a disaster. It’s hard to know how stuff like this will play out, every language evolves its own style and rhythm over time, and sometimes it takes reading and writing a lot of code to find the right balance.