-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: Go 2: Preference over snake case instead of camel case #64461
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
Comments
Maybe we could also migrate to spaces for indentation, because they have literally no advantage over tabs 👍 (/s if it wasn't obvious) |
Great way of making a constructive conversation, and so many arguments provided here. Thanks for the constructive criticism. /s if it wasn't obvious |
Sorry, I also find "it's unintuitive" not exactly an objective measure for anything. I myself can read and mentally parse a name just fine independent on if it's CamelCase, Snake_Case, Kebap-Case, or whatever someone may come up with. Do you have something "tangible"? |
This seems contradictory to Go's use of uppercase letters to export names in packages. Moreover, I don't think we could actually switch the ecosystem of developers and existing code even if we wished to. |
If it's not a comprehensive change (breaking backwards compat) - it will result in a split ecosystem where pre-snakeCase code is still camel and new code is snakeCase.. Now you have to live with camel and snake! Doesn't seem ideal. |
As a style guide, this can be adopted outside of the standard library, and if proven popular, we can then consider a change. |
I find it constructive that yes indeed it would split as a pre-snake-case and after-snake-case, this is constructive criticism and a problem to discuss about. Although, from what I see, the contribution community is rather aggressive to such a point to a point that it just literally insults my points by being sarcastic or ironic when I pointed out some serious points. So, I think the most serious problem here is that people just fear change. Just like with Generics, just like with any change on Golang's ecosystem, good or bad. The "pre-snake-case" and "after-snake-case" argument while constructive, is not a serious concern. It's not a breaking-feature concern. We'll just make linters that auto-format to snake-case. When every other serious language has defaulted to snake-case, Golang has chosen to go with CamelCase and with name conventions such as "MarshalJSON" instead of "MarshalJson" which means if you wanted to have another known abbreviation near JSON, you would have something like "MarshalJSONBSON" (depending on the use case, its just an example), which is obviously impractical. Snake case is made ... to just solve these things by default and be readable. So, I find that the issue is "not planned" more because people avert to change, rather than because it's not for the best. edit: It's natural that people avert to change, but people, do not try to convince me that CamelCase is more readable than snake_case. If you want to convince yourself that okay, but then read books with CamelCase instead of having spaces in between. InFactIWillMakeASentenceToProveMyCaseThatThisIsNotMadeToBeReadable. Period. |
Correct me if I'm wrong, but your point was that it was hard to read for you.
What is this supposed to express? This sound like a fallacy.
You are free to do so.
Maybe I missed who said that… Still, reading code and preferences is a highly individual thing and as such the experience differs from developer to developer. You seem to have big issues reading camel_case, while apparently most of the people see no distinct advantage in using SnakeCase instead. |
You can, but the linter always complains and you split your team into the "snake_case" team and the "camelCase" team. Like, that was my point from the start, to have a standardized name convention. Instead you specifically chose to be sarcastic with me and act like a smartass. |
Use as many emoji reactions as you want. They're not arguments against your own toxicity, of the aversion to change of the community that I see in some people here who even have the badge of the contributor, and maybe hold a responsibility to be a little bit more friendlier, professional, and the aversion to change, and not really any arguments against what I proposed. Just pure toxicity by being sarcastic with me, and emoji reactions .... great way to show what a friendly place for proposals this is, instead of providing actual arguments and having a friendly fruitful discussion. Like, I insulted nobody, yet people like you feel insulted because ... of a name convention?
|
Yet I never said one was more readable than the other, quite the opposite. At least to me there is no notable difference. Including "ImadeMyPointInMyLastSentence. Is_that_sufficient_for you?" Which is a terribly weak argument if one can read it just fine :D
As the proverb goes "Gofmt's style is no one's favorite, yet gofmt is everyone's favorite.", and I think this applies here as well.
There is one, it's camel_case. At least that is the established standard. Seeing how there has not been a lot of agreement with you in terms of legibility, I think it's rather safe to assume that this is a "you" problem.
You are certainly correct that my initial response was unreflected and has been a tad aggressive. This however, does not at all change the point that in my eyes the reasons given for a transition are not just very individual, but also have significant implications on the wider ecosystem that would arguably not be worth the tradeoff. One of the declared goals of Go is not to repeat the mess Python 2→3 has caused, and while only being stylistic, I think the snakeCase transition would hit a similar direction.
I was not in favour or against it, but after seeing it, it's usefulness is limited. I have seen one usecase where it has been a perfect fit, and otherwise has only changed the location of the typeswitch. Though I have to admit that I was fortunately wrong and there was not nearly enough generic-abuse as I would've expected. I also completely agree about enums, but this has absolutely nothing to do with snakeCase. Overall, I still think your provided arguments are rather weak and do not take into account some of the overall implications the transition would entail (including API breaks in pretty much every single stdlib package. Sure, Go2 is for just those, but see the point about the python debacle further up. This is not exclusively people being averse to change, but more that the perceived benefit in absolutely no way outweighs the cost of such a change.
Change your linter, my man. As far as I can see, the linter-light that comes with Go ( |
Go Programming Experience
Experienced
Other Languages Experience
Rust, NodeJS
Related Idea
Has this idea, or one like it, been proposed before?
In other languages, it's already a standard. In Golang, I'm not quite sure
Does this affect error handling?
Not at all
Is this about generics?
Nope.
Proposal
The proposal is to make it a standard to have Golang adhere to snake_case/Snake_case instead of camelCase/CamelCase.
Reason being:
Okay, Golang does not have Enums. As much as anybody would love to call this "enums", it's not, its pseudo-enums
It pollutes the namespace, it's not really intuitive, it does not have compiler support or anything of that short in case you want to validate an enum. You can only do that by inserting functions on the type itself and doing it by hand. Okay, my point is not to say how these are not enums, but how they pollute the namespace in such a way that it becomes unreadable. Imagine having a
longNameForAnEnumOne
and having to read all of that instead of just readinglong_name_for_an_enum_one
.Snake case is designed to have underscores as a replacement for spaces. CamelCase is literally designed to stick letters onto each other. It's counter-intuitive when trying to read someone's code or your own code when snake case was designed for this specific purpose to be easily readable.
I've programmed in Rust before, and while Rust may not be itself the most readable language of them all, the variable or function names are more than suffice. C++ too, Python, or other languages that usually follow the snake_case format and for a good reason. Golang is one of the few that has stepped back and doesn't use snake_case and uses camelCase instead. I don't quite understand why, and why the linter tries to enforce you by placing warnings for auto-fixing it.
It's completely reasonable to try to enforce one code-style for name convention with linting don't misunderstand me. But it's counter-intuitive to try to enforce a code-style that is designed to not be as readable as its competitors.
And best of all, it's backwards compatible, it has nothing to do with the code itself or the compiler at all. You can still write in snake_case, it's just that the compiler and the IDE will complain, but your code will work it's not that it's against the principles of the compiler.
Language Spec Changes
No language spec changes. Just the philosophy that "everything should be written in CamelCase" and either leave some freedom on the programming team deciding the best convention, or enforce the one that is just ... objectively the best out there for naming convention. The one that is designed to be readable because it's designed to separate words with a "space"-like symbol.
Informal Change
No response
Is this change backward compatible?
Totally.
Orthogonality: How does this change interact or overlap with existing features?
It does not interact with any feature.
Would this change make Go easier or harder to learn, and why?
It makes it easier to read, write and maintain code or even write long pseudo-enums.
Cost Description
The linter would have to stop complaining or try to enforce snake_case instead at least.
Changes to Go ToolChain
No changes except that gofmt would probably have to enforce another naming convention.
Performance Costs
No performance cost, it's just naming convention
Prototype
Self-understandable what the prototype is or should be.
Instead of this
have this
The text was updated successfully, but these errors were encountered: