The Naming Conventions you MUST Know when Coding

camelCase, PascalCase, snake_case and kebab case. What?

You might be aware that there are naming conventions in your chosen programming language.

Perhaps you should be aware of this: it helps to make your code readable and understandable. Plus will help you get through code reviews…

Difficulty: Beginner | Easy | Normal | Challenging

Prerequisites:

  • None, but for practical purposes it would be useful to be able to produce a “Hello, World!” application in your chosen programming language

Terminology

Hyphen: The — character

Brochette-case: A naming convention where the name is formed of multiple words joined as a single word separated by _, but the first letter of each word is capitalized. The first letter is usually in upper case

Kebab case: A naming convention where the name is formed of multiple words joined as a single word separated by _, but the first letter of each word is capitalized. The first letter is usually in upper case

lowerCamelCase: A naming convention where the name is formed of multiple words joined as a single word, but the first letter of each word is capitalized. The first letter is in lower case

Pascal case: A naming convention where the name is formed of multiple words joined as a single word, but the first letter of each word is capitalized. The first letter is in upper case

Snake case: A naming convention where the name is formed of multiple words joined as a single word separated by _, but the first letter of each word is capitalized. The first letter is usually in upper case

Underscore: The _ character

UpperCamelCase: A naming convention where the name is formed of multiple words joined as a single word, but the first letter of each word is capitalized. The first letter is in upper case

The naming conventions

Which naming convention is suitable for your programming language is usually defined within a relevant style guide (or the table that I’ve prepared for you towards the end of this article).

Camel Case

Camel case is a fairly common convention. In fact, it comes in two different types: Upper and Lower — so let us explore these two conventions. Style guidelines usually specify which variety of Camel case is suitable for which situation you would need in your language.

Camel case is similar to Hungarian notation, and it is claimed that the use of camel case dates back to 1979 at Xerox PARC.

Upper Camel Case

These start with an upper case letter, and work like several words are pushed together to make the name, with each individual word being capitalised.

First + Number = FirstNumber

Examples: MyFunc(), MyVar, Name, Test

lower Camel Case

These start with an lower case letter, and work like several words are pushed together to make the name, with each individual word being capitalised apart from the first.

first + Number = firstNumber

Examples: myFunc(), myVar, name, test

Pascal Case

Pascal case is another name for Upper camel case

Dromedary Case

Dromedary case is another name for lower camel case

Snake case

Snake case starts with a lower case letter, and uses an underscore to separate words (although some variations start with an upper case).

Generally associated with the C programming language, although it actually started life with no particular name:

first + _ + Number = first_Number

Examples: my_func(), my_var, name, test

Kebab case / Brochette-case

Kebab case is a dreadful name for snake case, while simply using a hyphen in between the words. Perhaps this is why it is also known as Brochette-case im certain circles

first + _ + Number = first_Number

Examples: my_func(), my_var, name, test

The Languages table:

Here is a help sheet for common languages:

Image for post
Image for post

Conclusion

This has been a quick journey through some naming conventions. It doesn’t cover everything, and you will need to consult style guides for that perfect code review.

However I hope this has given you a start and some understanding of what is involved in naming in programming.

Happy coding!

The Twitter contact:

Any questions? You can get in touch with me here

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store