3 ms·
> 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 comm
by 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.