-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wiki: CodeReviewComments change - "Variable Names" topic #38912
Comments
Go is making an intentional choice here, and it is reflected in the standard library. You should make your own choices in your own code, but we're comfortable with the general Go style. |
Thanks for answering! What I understand from what you say is that you (go programmers) like this approach (or at least you are OK with it). Are there any arguments or any real reasons besides taste or indifference? To me it's clear that when you work in multiple go projects, what will happen is that you will find one project that e.g. uses "m" for message and another that uses "m" for memory and you will struggle to remind your self every time you read code what "m" stands for in that context. Seems to me a bad choice and not only to newcomers like myself. I'm not saying that it can not be done right. Maybe the intent of more experienced go programmers is to use short letters when understanding does not depend on variable names (local variables for tiny functions that have a clear name maybe) If that's the case then if should be more clear, because the idea I have is that people usually are using it everywhere without thinking |
The argument is fairly simple: long variable names take more space on the screen and are harder to read at a glance. If a variable only lives for five lines, it generally doesn't need a long name. In general, the longer the variable lifetime, the more descriptive the name should be. |
I don't fully disagree with that. just think the advise should be the other way around. The msg It's not clear and I'm afraid programmers started to always use single letters. even in simple blog examples or stack-overflow. seems to me that it became a cultural thing of Go. About the argument, You never know where a project goes and a variable "m" that in used in just 5 lines today might have to be renamed tomorrow to "message" because suddenly code got bigger? (too many possibilities to be discussed here ofc) Anyway I'm probably wrong (judging from the dislikes 😄) and I respect that. Thank you for your time 👍 If anyone reading this want to buy a big screen come and send me a msg |
It's a general advisable in every basically every programming language to prefer descriptive variables over single letter ones (generally)
I don't understand why or how this bad practice of using single letter variable everywhere become so popular in goland
To me, as a new comer it makes code a lot harder to read. Go programmers are often taken the "Variable names in Go should be short rather than long" too far and making everything a lot harder to read
If there is a place where programmers should care about others it's this one - documentation
Please update docs to advise programmers to prefer descriptive names and only use short in general conventions (exceptionally)
The text was updated successfully, but these errors were encountered: