Naming Styles
In programming, you often have to combine multiple words into one-word-like in order to describe a single entity. There are multiple conventions, though each programming language has adopted some over the others.
The four most commonly used cases are:
- snake_case separates words with underscores and all words are in lowercase
- kebab-case is like snake_case but words are separated by hyphens instead of underscores
- PascalCase separates words by capitalizing the first letter of each word
- camelCase is like PascalCase except the very first letter is in lower case
I like to type the names of above naming styles in the format that they represent. If I’m sharing a feedback in PR, I might say “Can you change this variable to camelCase for consistency?”
Conventions
Each language uses multiple naming styles where each style is dedicated for specific purposes. Those cases are:
- variable and function names are often in camelCase or snake_case
- camelCase: JavaScript/TypeScript, Java, C#
- snake_case: Python, Rust
- classes are mostly in PascalCase
- constants are mostly in SCREAMING_SNAKE_CASE, which is snake_case but in all caps
- file and module names seem to be all over the place.
Frameworks
But frameworks on top of a programming language can have their own convention too!
I happened to work on Vue.js project briefly and it looked like everything was in kebab-case despite the fact that it’s a JavaScript framework.’
Conclusion
Proper naming in programming is crucial, as it makes code more comprehensible. Good names clarify what each entity represents, facilitating understanding of interactions and underlying business logic.
p.s. Some notable mentions of other naming styles include:
- dot.case
- Train-Case
- UPPERCASE
- stringHungarianNotation
- Hungarian Notation has its type prefixed (e.g. string, int) e.g. stringName, intAge