coding standard guidelines
We are not here to defend the case for why using conventions; there is a whole different article about that that you can read here: Variable Naming Conventions as a part of our coding standas and guidelines series of lessons.
The Snake Case or snake_case
is one of the most used naming conventions because it makes variables really easy to read; you can argue that snake_case
is more readable to the eyes than cameCase
.
_
instead of space to separate words.For example, a variable representing the number of students in a class might be named "num_students".
numberOfStudents
is incorrect because you need to separate words with underscore _
; using capital letters is for camelCase or PascalCase.1_apple
incorrect because you can't use numbers at the beginning._
at the beginning; this is used a lot in "private variables".Note: You can see cases where
Snake Case
is used in other languages like C++, Swift, etc. But we are only adding to the above list the programming languages explicitly stating which is the preferred naming convention.
Nothing, you can use any convention you want; this is only a suggestion. But please bare in mind that other developers and yourself in the future will appreciate it a lot if you comply with the best practices.
In the end, it's all about readability; the goal is for you or any developer in the future to read the code easily and understand everything quickly. Naming consistency is one of the most critical factors in achieving this.