I can’t be the only one who forgets what each naming convention I should be using between different languages. Especially as there are variations between each one.
So, just so that I could see how many I could cover, I thought it would be a great idea to make a list here, with a brief description of each type, and any varying names that come with them. Hopefully, writing them down and looking into each one myself would help it stick.
This isn’t a conclusive list. Not yet, at least. I’m not covering every obscure one. For now, it’s just a brief introduction to some of the most widely used naming conventions, and some of the ones that I use on a regular basis.
Naming conventions aren’t just used to name variables in programming languages either, they can be used in file names, folders and even company names. Like
ebay using the first case on the list.
Sometimes called Camel Caps, this is one of the most widely used naming conventions and can be spread across most of the programming languages.
It’s used with the capitalisation of every word except the first letter, so
thisIsAVariable. Sometimes this can be referred to as Lower Camel Case.
Other variations of this extend to capitalising the first letter, so
CamelCase for example. This way is called Upper Camel Case, or Captial Camel Case , or more commonly, Pascal Case.
Snake case involves separating the words with an underscore, like
snake_case. Most commonly used with lower case letters, although I have seen them used with capital letters in things like session variable names.
Kebab case is very similar to Snake Case, except that it separates each word with a hyphen. This style is widely used in CSS files as people style their websites. So you would see
Simply typing out your variables in lower case is called Flat Case. No requirement for hyphens or underscores, or even separating out each word with a capital.
Using flat case does make things very difficult to read on occasion. It’s the same reason that there have been some monumental Hast Tag fails, because it uses flat case.
I won’t list too many fails here, because most of them end up a little x-rated. But the hast tag for Powergen Italia looks bad as #powergenitalia.
I’m not totally sure if Upper Case requires you to use underscores between each word. I have seen examples of using underscores and some without. So just Flat Case with the caps lock on.
I have used Upper Case with underscores, which I use for temporary variables within PHP. I’m not sure that’s what anybody else does, but it works for me.
Studly caps is probably not something you may see in many code bases, but it’s interesting enough to be worth a mention.
It requires more effort to both type and read than the other cases mentioned above. So the reason for using it must allow for something that the other do not.
If you are constrained by white space but want to use have restrictions on naming, then this can save the day.
Also, Studly allows for hidden words within itself, Hotmail was original stylised as
HoTMaiL with includes HTML as upper-case.
Some of these have a use for different languages, or different environments. I currently tend to stick to Snake case for PHP, kebab case for CSS, and Camel Case for anything else. There an’t many options when it comes to naming conventions, and are often created in languages based on requirement or restrictions.
If you have anything interesting that you think I should add to the list, then let me know in the comments below.Tags: conventions, naming, programming, standard, style