camelCase vs snake_case
Been obsessing about camelCase vs snake_case for years. Still no conclusion. Scientifically, by pop, by ease of typing... No conclusion. I've pretty much read all literature about them in past years.
Most existing lang conventions are idiotic. Their formation is pretty much historical. Not by any logical basis.
There are a couple of somewhat scientific studies on camelCase vs snake_case on accuracy or speed of recognization. But is inconclusive.
If there is any common practice across languages, it is that, StudCamelCase is usually for class names, while snake_case for variables. But note, functional languages don't have class. So, this “common” is only somewhat common among imperative languages.
The other convention that's somewhat pop across languages, is ALLCAPS for constants, and _start for unused variable.
If we go by ease of typing, then by default camelCase is easier to type. This is because on normal keyboard, the LOW LINE _ character is hard to type. It requires pressing Shift and using pinky finger.
However, this is easily fixed, if you have a easy key that inserts _ directly. e.g. On many batman keyboards you can do this. Then, snake_case is actually easier to type than camelCase. (but, if you turn on sticky keys, then camelCase is easier again than low line.)
[see Computer Languages Characters Frequency]
But if we go by which is textually better, then snake_case is better. Because
- It is syntactically simpler, by using a delimiter.
- It is semantically simpler, no XMLHTTPConnection vs XmlHTTPConnection issue.
- Does not require the complexity of capital case. e.g. Can be used on Chinese, or any alphabet or symbol set that does not have cases.
- You can still have the freedom to use capital case.
- Can be used universally. e.g. All computer systems accept low line character. But they may not accept capital case or has complex rules about case sensitivity.
However, for programing language identifiers, i always came back to camelCase, because:
programing language identifiers are blobs, because, you are not really writing prose where each words needs to be read-over, but rather, you have a blob of things that you want to easily identify at a glance — identifiers — get it?
In fact, there is advantage that it not be full English words, because it's impossible to name function and variable so that they fully describe what purpose they serve. Rather, you name them, as a identifier, a blob, as ID. The English in it serve as a reminder what function or variable is used for.
problem with snake_case is
With camelCase, by its very nature,
you don't try to do that.
and when they both are “same”, camelCase is shorter and easier to identify.
i'm the type of guy who is deeply obsessed with trivia, like, camelCase vs snake_case.
over the past few years, i've eagerly read anything written on the subject that hit me. Here's a few generic ones, discarding those language specific guides.
[An Eye Tracking Study on camelCase and under_score Identifier Styles By Bonita Sharif And Jonathan I Maletic, Department Of Computer Science, Kent State University. At http://www.cs.kent.edu/~jmaletic/papers/ICPC2010-CamelCaseUnderScoreClouds.pdf , accessed on 2015-09-07 ]
[To CamelCase or Under_score By Dave Binkley, Marcia Davis, Dawn Lawrie, Christopher Morrell. At http://www.cs.loyola.edu/~binkley/papers/icpc09-clouds.pdf , accessed on 2015-04-15 ]
[Why the Twisted coding standard is better than PEP8 (although you still shouldn't care) By Glyph Lefkowitz. At http://glyph.twistedmatrix.com/2012/10/a-tired-hobgoblin.html , accessed on 2015-04-15 ]
[IHateCamelCase By Yossi Kreinin. At http://yosefk.com/blog/ihatecamelcase.html , accessed on 2015-04-15 ]
after reading them all, all the reasons are like hogwash.
Back to early 1990s, i'm deeply a believer of the snake_case. Because, that is a unambiguous and reversible way to map space-separated words into computer languages shortcomings of not allowing space. Some are thinking, lisp-style-with-hyphen-is-best, but actually no, because hyphen is used in English too. So, by using hyphen as separated, you create the ambiguity of a phrase that has hyphen in the first place. For example,
[see Hyphenated Words]
But then, around 2009 or so, i started to like camelCase. Because, it's really convenient to type.
But even so, convenience of typing shouldn't count, because that's the keyboard problem, a completely separate issue, which can be easily solved. For example, i use a emacs key system that ...........
and, but, some say camelCase is harder to read than under_score. That's
not true, because words used in computer lang are identifiers. When
you_start_to_to_have_long_names_like_this, the underscore
camp gets edgy, because, you are not really writing prose where each words
needs to be read-over, but rather, you have a blob of things that you want
to easily identify at a glance — identifiers — get it?
Letter Case in Programing Languages
- CSS (by convention)
- emacs lisp
mixed camelCase and snake_case
If you have a question, put $5 at patreon and message me.