5 ms·
> 2.1. Choose identifiers for clarity, not brevity This is a real problem in Go these days, people use one and two letter vars quite a bit which makes reading
by argd678 8y ago
> 2.1. Choose identifiers for clarity, not brevity
This is a real problem in Go these days, people use one and two letter vars quite a bit which makes reading code you’re not familiar with practically impossible. On one project we simply switched to semi-java length like names since our customers couldn’t read the code.
- entity345 8y agoSince when are variables names a language issue? There is no such thing as "Java length like names", or whatever. There are good practices and bad practices and they are universal.
- noir_lord 8y agoThey usually aren't however they can be an issue if the idiomatic style trends towards towards bad ones.
- futureastronaut 8y agoDogmatism and Go are peas in a pod. If your variable is longer than one character you're a dirty Java programmer, or something to that effect.
- croshan 8y agoIt's really more of a language community issue, but communities of a language are commonly referred to by the name of the language itself.
- entity345 8y agoI'm sure there are many actual professionals using Go. Not just script kiddies. I happen to be learning Go coming from a C background. I find "The Go Programming Language" by Donovan and Kernighan exemplary and the decades of experience that went into the language really show.
- croshan 8y agoNo need for insinuations, that's not a point of contention. If you look past the book, and directly at the STL, you'll find a common example: the "fmt" library, shortened to save three letters. Or compare the verbosity of these two examples from language docs, and the length and descriptiveness of variable names in them: https://docs.oracle.com/javase/tutorial/essential/io/cl.html https://docs.oracle.com/javase/tutorial/essential/io/cl.html to https://golang.org/pkg/bufio/#example_Scanner_emptyFinalToken https://golang.org/pkg/bufio/#example_Scanner_emptyFinalToke... I agree, it's a great language. These naming conventions are part of its developers and community.
- entity345 8y agoNaming conventions are part of your own practices and processes. There is no issue with having short names to describe well-known entities part of the language, or trivial code. Your example from pkg.bufio is trivial and but still the variables names are meaningful. There is a difference between clearly and meaningful, and verbose. Your example from Java is not very different. I feel that the point is not being understood here.
- aczerepinski 8y agoI disagree with this because I personally change my coding style based on the language I’m writing. When I write Go I do use one letter variable names like u := User because I’m modeling what I see from some of the top Go developers (core team members, etc). When I write JS I usually follow the popular airbnb style guide and order my code differently than I would in any other language. When I write ruby I look for naming conventions that read like English. I’m always trying to write idiomatic code that will feel familiar to readers who write that language.
- argd678 8y agoGood naming is almost all that matters infact, that’s how you express your intentions to the reader. You can dispense with all other constructs in a programming language as long as it’s turing complete, but no one would be able to understand your program then.
- freyir 8y agoIf you’ve seen any amount of Go and Java code (starting with, say, the standard libraries), you’d know these communities take very different approaches to variable names.
- entity345 8y agoThe point is that you do not choose the way to name variables based on a sheepish "it's the way the community does it". You're responsible for your own code, and your organisation's code. It has nothing to do with the language.
- sacado2 8y agoBut then you end up with a non idiomatic coding style, which may be an issue if your code is open-sourced. I'd be very wary of a Java program where variable names are snake_cased, for instance: did they do it for a good reason? Are they just beginning java developers? Will I run into other ad hoc coding practice when trying to understand/maintain/extend their code?
- entity345 8y agoAgain, there is nothing "idiomatic" is poor naming, nor do I see what open source has to do with it...
- sacado2 8y ago"Poor naming" is subjective. What is the correct name for a variable that associates a user's name with its configuration profile? userNameToConfigurationProfile? user_name_to_configuration_profile? userToConfig? profiles? userCfg? If there was one true way to do it, everybody would adopt it (unless you consider some communities are just plain dumb).
- entity345 8y agoWe're discussing 'good naming' as defined in the article and first comment of this comments thread: > 2.1. Choose identifiers for clarity, not brevity Cosmetic considerations like snake or camel case are irrelevant. The advice above is standard good practice that is not dependent on the language used.