camelCase vs snake_case

By Xah Lee. Date: . Last updated: .

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 convension 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.

[see Computer Languages Characters Frequency]

[see Ergonomic Keyboard Reviews]

But if we go by which is textually better, then snake_case is better. Because

  1. It is syntactically simpler, by using a delimiter.
  2. It is semantically simpler, no XMLHTTPConnection vs XmlHTTPConnection issue.
  3. 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.
  4. You can still have the freedom to use capital case.
  5. 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 letter case.

Note: this essay is unfinished.

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 , accessed on 2015-09-07 ]

[To CamelCase or Under_score By Dave Binkley, Marcia Davis, Dawn Lawrie, Christopher Morrell. At , accessed on 2015-04-15 ]

[Why the Twisted coding standard is better than PEP8 (although you still shouldn't care) By Glyph Lefkowitz. At , accessed on 2015-04-15 ]

[IHateCamelCase By Yossi Kreinin. At , accessed on 2015-04-15 ]


Snake case

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, stdin_stand-in

[see Hyphenated Words]

[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 bullshittish, 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?

If you have a question, put $5 at patreon and message me.