Naming Conventions in Clean Coding Practices

Being a good programmer is a real struggle if you are not a smart programmer. Clean coding practices are something a smart programmer should possess with. The program you have written should be clean and presentable. Now you might be wondering why presentable is important for your code. You might be thinking if your code is working pretty well that is enough. But that is not the real scenario. Now let’s see why your code should be presentable.

  • When you are working with a team, your code should be understandable and readable for other programmers.
  • For your future reference. If you have to refer to a code that you have written a time before, you should be able to read it and understand it.
  • It is easier to modify the code when it is needed.
  • Increase maintainability. Testing and adding new features becomes easier if the code is clean and readable.
  • After all, a piece of code has enough complexity. Why you are adding more struggles to it. Keep it simple as possible.

The naming convention is one of the leading clean coding practices. It improves the readability of the code. Readability is a must when you are working on a project with a team. Other developers, testers should be able to read your code. If standard methods are using to name variables, functions, classes it becomes clearer to refer to the code. Not only that but also naming files in a project should be done in one common way. It is advisable to use some common and standard naming conventions when writing your code. Now let’s see some common naming conventions.

Courtesy: www.pixabay.com

Here, the first letter of each word you are using should be capital except in the first word. Symbols and spaces are not allowed in between words. This naming convention is identified as the Camel case (camelCase) as the combined string is written like the humps of a camel. Some programmers prefer to use Camel case as CamelCase and some prefer to use as camelCase. To address the confusion between the two styles, CamelCase is called the Upper camel case and then it converts into Pascal case which is going to explain under the next point and camelCase is referred to as Lower camel case. Camel case is so often used to name variables.

Ex:- firstName, newNumber

Courtesy: www.biography.com

In Pascal case, the first letter of each word in the combined word should be capitalized. As in the Camel case, symbols and spaces are not permitted in between words. Programmers use Pascal code mostly to name functions, classes, and other objects.

Ex:- MaxNumber, NewObject

Courtesy: www.pixabay.com

In Snake case, two words are combined into one string with underscores. As spaces are not allowed in naming in most programming languages spaces are replaced with underscores. You can name variables, methods either using all caps lock on or all caps lock off.

Ex:- find_max, FIND_MAX

Courtesy: www.pixabay.com

In the Kebab case, words are combined together with hyphens and as meats and vegetables compound in a kebab. Hyphens are used in between words and create a single string as spaces are not allowed in naming variables, functions, classes, and methods in programming. The programmers use the Kebab case to name variables instead of the Camel case.

Ex:- new-variable, add-numbers

Use the these naming convention cases smartly in naming variables, methods, classes, functions and be a smart programmer.

This is the end of the article and I hope this would be helpful to you all.

Thank you!!!

Undergraduate-Faculty of Information Technology | University of Moratuwa | Sri Lanka