"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why we use snake_case for variables and camelCase for functions

Why we use snake_case for variables and camelCase for functions

Published on 2024-08-24
Browse:277

Why we use snake_case for variables and camelCase for functions

To be less stressed, and therefor better programmers, we have to do our best to free our code from bullshit that makes it a hard to maintain, and hard to onboard new devs-to.

We use the same name for database fields, JSON property names returned from an API, the HTML form field name attributes, and finally, the Javascript variable names that contain those database-originating values. Naming your data exactly the same in all layers of the stack frees you from having to keep a mental mapping of what is what. Discipline yourself to enforce this rule, and you will be a less stressed programmer.

We use snake case for naming variables we define ourselves. It sets them apart from most thing that are defined in a Library, because most libraries use camel case for variable names.

We use full words instead of acronyms, and if something is an array, it is spelled plural. This helps people from all nationalities understand what a piece of data is, without knowing shorthand versions of words.

We use camel case for function names simply because it allows us to quickly identify that an identifier is a function, and not a variable. Yes, I know functions can be saved as values, but the difference is that you can't call a primitive/object/array value by adding parentheses to it. That's where the line between function and value is, and having a visual cue to tell one from the other will also make you a less stressed programmer.

Release Statement This article is reproduced at: https://dev.to/alexleduc76/why-we-use-snakecase-for-variables-and-camelcase-for-functions-4hm9?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3