Snakes and Camels?
I was intrigued by an email from a vendor that mentioned snakes and camel case for the field names from an API call. “What snakes and camels? Since when do animals come partying in our project?”, I wondered. These terms are quite rarely heard these days. Typically people deal with title case, uppercase, lowercase etc., so I decided to do some research to find out what is it about.
Camel case and snake case are different forms of variable naming convention style. These two are the more popular ones that programmers use. Camel case and snake case stand at opposite ends of the naming convention spectrum and we shall see how and what they are like in this article. You might even be using them without knowing what they are called, just like me.
Snake case uses underscore between words to create separation. As variable names cannot contain spaces, this reduces readability when multiple words are combined to describe its purpose. Snake case tries to minimize this shortcoming.
It is immediately apparent why it is called a snake case. It do looks like a snake wiggling amongst the codes. One study has found that readers can recognize snake case variable names more quickly than camel case.
Camel case uses capitalization of the first character of each word to denote the start of a new word. It is also known as Pascal case or upper camel case. When it is not, it is often referred to as lower camel case.
It is obvious why it is called a camel case. It does looks like it has a lot of humps doesn’t it. Do note that it is different from title case where it retains space as word separators. Camel case has been criticized as not been as readable compared to other methods due to the removal if spaces (and/or alternative replacements) and uppercasing of every word.
From the above examples, it seems pretty obvious that snake case provides better readability, but that is just my opinion. Some people find camel case easier to read. To me readability is especially important in coding. If your team member or others are unable to understand it, it is useless. The coding language and platform that you are using do affect your choice of naming convention. It is better to follow the standards (if there are any).
aka plaindoufu View all posts by doufu
Originally published at http://doufu.wordpress.com on June 15, 2022.