Programming Naming Conventions
Benedict Anthony
October 15th 2024What are Naming Conventions in Programming?
Conventions exist in addition to the clear and fast rules that come with each programming language. These are sets of criteria that the vast majority of developers agree upon. Naming conventions are among the most frequent. Because programmers name a lot of things. Examples include variables, functions, classes, methods, and interfaces. Throughout the years, developers have utilized several case types to identify different entities in their code. And four of those turned out to be the most popular. They are:
Camel Case
In camel case, you start a name with a small letter. If the name has multiple words, the later words will start with a capital letter: Here are some examples of camel case: firstName and lastName.
Snake Case
In snake case, you begin the name with a little letter, just as you would in camel. If the name contains multiple words, the latter words will begin with small letters and be separated by an underscore (_). Here are some examples of snake case: first_name and last_name.
Kebab Case
Kebab case is similar to snake case, but you use a hyphen (-) instead of an underscore (_) to separate the words. Here are some examples of Kebab case: first-name and last-name.
Pascal Case
Unlike the previous instances, names in Pascal case begin with a capital letter. In the case of names with numerous words, all words will begin with capital letters. Here are some examples of pascal case: FirstName and LastName.
When to Use Each Naming Convention
Now, depending on the language and what you're naming, the appropriate case type can vary. For example, according to the PEP 8 - Style Guide for Python Code, variable and function names should be in snake case. Python and JavaScript both require you to use Pascal case when naming classes, even if they have different standards for naming variables and functions. For almost every widely used programming language, there are style guidelines available. Here are a few of the most widely utilized ones: Python - PEP 8 β Style Guide for Python Code, JavaScript - Airbnb JavaScript Style Guide, Java - Java style guide, C# - C# Coding Convention, Go - Uber Go Style Guide, C++ - C++ Core Guidelines, PHP - PSR-12: Extended Coding Style. These are a few of the guides that I have previously used. There are further guides available. Please investigate further and select the one that appeals to you. Just make sure that the development community truly thinks highly of the instruction you're following.
Take away
The most common naming conventions are listed here, and you should be aware of them. You can browse through the style guide for the language you're using to find out more about the various name conventions. It's crucial to understand the customs of the language you're studying. Although breaking conventions won't damage your code, it will become less consistent and more difficult to work with. On the other hand, if you adhere to these straightforward rules, your code will be much easier to read and manipulate. So please, be a good neighbor and observe the customs.