Why camel case?

Effective Go, mixed caps:
Finally, the convention in Go is to use MixedCaps or mixedCaps rather than underscores to write multiword names.

I suppose snake case is much easier to understand. Compare aLongVariable and a_long_variable. Why did they decide to make camel case inherent to Go and who are they?

Hi,

There is one thing that is important to understand. If you capitalize your identifiers, then they are exported from the package. In Go, always using variable names like MixedCaps may get you in trouble as your program grows. If you want to use camel case, use mixedCaps instead, with MixedCaps (capitalized) only for exported variables, types, and functions.

Go does not require that you use camel case. The compiler is happy to accept identifiers like variable_name, and you are free to use that method for naming. I do that all the time because I’m mainly writing for my own purposes, and after learning that method for C, I never found camel case to have any compelling advantage. In fact, I find it much more difficult to read.

But if you are writing as part of an organization (employer or even just an Open Source project), then it can be important to standardize on a local convention, or more global conventional idiomatic use. And that’s just to make it easier for many programmers to work on the same project.

So just do what is required for the kind of programming you do.

3 Likes

Is this the place where Scheme developers ask why they don’t use a-long-variable? Standards are there to be made and then used so that the users of a codebase easily find into that code. It’s the same like the work of gofmt. I remember all these discussions 9 years ago, opening brace on end of line or on new line. But it today ensures a very similar looking codebase in many projects, which is helping. So asking “why” is a meta-question in this case, at least in a forum. If you really want to know it, may be for a book about the history of Go, try to contact Rob, Robert, or Ken.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.