Right way to Code and Syntax with Camel case vs pascal case

Hi everyone, coming back to Developer series after long, I will be writing today about, a very basic thing that every coder, actually a new coder misses. That is the right way to code that follows some rules and acceptable and understandable to all. So, let’s start with right syntax and what it is with examples.

Also read Developer Terminology – You Need to Know

The Right Way to Code and Syntax

As we all know coding is to provide solutions to problems. But during the development process, there are more problems that coders face with the development phase; Actually saying, for solving a simple problem, we create more problems and do various iterations for fixing and then finally reach to a solution. There can be many issues to the problems. So, I will be telling about these simple coding syntax issues in details.

You all must be thinking now what the right way could be I am going to write about. So let me break it into two parts. First, we will look over semantics and then Syntax. So, let’s do divide the topic into two parts:

1. Semantic

2. Syntactic

Semantics

As we know we write code to do our task and optimize it. So let take the example of students. There are multiple things related to students like class, subject, teachers, course and much more. Let say we want to create a web application that manages all data similarly like as we may do without application in the real life manually. If we are not clear with what our fields should be, we will have a problem of understanding, mainly in multi team projects.

Also read Free Graphic Design Websites for Graphic Designers

Let assume, we have two developers who working on different modules each for the same project but coding separately; without talking to each other and explaining each other’s code. Let say for roll number field; one set property as roll_no and other st_roll, they both appear different and not understandable. But if we simply write, student_roll_no. The renaming explains itself and needs no explanation at all and have same meaning for everyone. So, the meaning of a word, sentence or any letter is the semantics; that can explain itself resembling to real world application. If semantics are good, there is no need to explain code, no code conflicts and increased productivity within different teams.

Also read Text Editors for Code

Similarly like during creating methods,  some may save name as stMarkSave() that creates some confusion of what the function does, but if we have written like saveStudentMarks(), it is self-explanatory and needs no one to explain. So if we use correct semantics, then there will be no confusion.

Some may think, that writing method names or declaring variables with shortened keywords like st in place of the student are good, but it leads to complexity when a project grows up and you need to go through each and every file of the project to check what and why it was for, This increases complexity, debugging becomes difficult and cost grows to maintain and develop. So better to use full words, as we today have no limits on storage or like as issue that was before a decade ago or more.

Some tips for good semantics are:

  1. Don’t shorten the words and try to use complete word unless the words are really long.
  2. Use self-explanatory names like currentDate or current_date instead of curDt or cDate or c_dt.
  3. Use Cases like Camel Case or Pascal Case for names with multiple words.
  4. Use declarative names like saveStudent in place of sv_stud or anything short.
  5. Use variables with the full name like student_roll_no or studentRollNo, it reduces confusion.

Syntactic

Just like semantics, the syntax is also a source of confusion. The syntax is the way we write code and multiple words together like student_class or studentClass.There are different types of case for syntax:

1. CamelCase

In CamelCase the initial letter of the first word starts with small case, and capital for remaining letters like studentClass, studentRollNo etc. Used for in file variables naming and naming helper services or exported low order functions.

2. Snake case

In SnakeCase all letters are small and joined by an underscore (_) like student_name, class_name, marks_of_maths. Used for file names, scripts etc.

3. Kebab case

In this we join letters by (-) sign like class-name, student-name. Used in files naming and shell scripts.

4. Pascal Case

Subset of CamelCase but the initial letter is also capitalized like StudentClass used for naming Classes and High Order Functional components in JAVA, ReactJS, Angular.

Also read Tips to become a Pro Developer

Bonus Tip

Along semantics and syntax, there are many things that can help in writing good code. The cases like using a single method for multiple logics is bad, but writing method that does a single task is good like a method that calculates simple interest as well compound interest both is bad, but if we have two separate methods, one for simple interest and one for the compound interest. These are the basic principles for good programming. Below is the link you can visit to read more about this.

Solid Principles of CodingLink 1 LInk2

I hope you like the post, if yes then do share with your friends and comment down what you think of this one and let us know your views in the comments so we can improve our content. Keep sharing as sharing is caring. Stay connected and keep checking for more updates coming.

Content Protection by DMCA.com
Balvinder Singh
Balvinder Singh

Founder And Editor at Tekraze.com. Loves to write about technology, gaming, business, tips and tricks. Working as a Senior Software Engineer in Infosys India. Exploring different blockchains as well.

Articles: 367

Leave a Reply

Your email address will not be published. Required fields are marked *