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 onboard new devs-to.

We use the same name for database fields, JSON property names returned from an API, …


This content originally appeared on DEV Community and was authored by Alexandre Leduc

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 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 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.


This content originally appeared on DEV Community and was authored by Alexandre Leduc


Print Share Comment Cite Upload Translate Updates
APA

Alexandre Leduc | Sciencx (2024-08-20T22:55:01+00:00) Why we use snake_case for variables and camelCase for functions. Retrieved from https://www.scien.cx/2024/08/20/why-we-use-snake_case-for-variables-and-camelcase-for-functions/

MLA
" » Why we use snake_case for variables and camelCase for functions." Alexandre Leduc | Sciencx - Tuesday August 20, 2024, https://www.scien.cx/2024/08/20/why-we-use-snake_case-for-variables-and-camelcase-for-functions/
HARVARD
Alexandre Leduc | Sciencx Tuesday August 20, 2024 » Why we use snake_case for variables and camelCase for functions., viewed ,<https://www.scien.cx/2024/08/20/why-we-use-snake_case-for-variables-and-camelcase-for-functions/>
VANCOUVER
Alexandre Leduc | Sciencx - » Why we use snake_case for variables and camelCase for functions. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/20/why-we-use-snake_case-for-variables-and-camelcase-for-functions/
CHICAGO
" » Why we use snake_case for variables and camelCase for functions." Alexandre Leduc | Sciencx - Accessed . https://www.scien.cx/2024/08/20/why-we-use-snake_case-for-variables-and-camelcase-for-functions/
IEEE
" » Why we use snake_case for variables and camelCase for functions." Alexandre Leduc | Sciencx [Online]. Available: https://www.scien.cx/2024/08/20/why-we-use-snake_case-for-variables-and-camelcase-for-functions/. [Accessed: ]
rf:citation
» Why we use snake_case for variables and camelCase for functions | Alexandre Leduc | Sciencx | https://www.scien.cx/2024/08/20/why-we-use-snake_case-for-variables-and-camelcase-for-functions/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.