Hello DEV Community!
I'm curious to know whether you prefer snake case or camel case? If you could create your own programming language would you have snake case or camel case as the standard? In case you don't know what snake/camel case is here is an example:
Python example (Python uses snake case):
def snake_case():
print("Snake case is all words are separated by a '_'")
Javascript example (Javascript uses camel case):
const camelCase() => {
console.log("Camel case is every word except for the first one is capitalized.")
}
Let me know which one you like best!
Henry
Top comments (23)
It's not a matter of which one I like best, it's a matter of following the code conventions of the language I'm writing at the moment, this makes the code more readable for other programmers using the same language within the organization.
For instance, in Python, if you don't follow PEP8 (which is the one defining the code conventions) your code might be difficult to read, for example:
In this dummy code snippet, if we know it's following PEP8, we know that
UserProfile
andOperationResultHandler
are a classes, not a functions, if PEP8 wasn't enforced, I would have to go to where each symbol is defined to find out whether they are classes or functions so that I read (and edit) the code with more confidence. Moreover, any new joiner familiar with python will be able to read it without going back and forth to each symbol definition because it follows the agreed code convention.To me, it's not a matter of choosing the convention for your project and sticking to it, it's about getting familiar with the convention for the language you're using and following it.
Very well demonstrated! I used to be an adamant camelCase advocate (coming from JavaScript). When I went into Rust (which uses snake_case), I was horrified by the language convention. It took me a while to accept that it's just better to go with language conventions than to fight the community norms.
@somedood I went through something similar! When I was learning JS/TS and then went to Python and Rust, I found it hard to use snake_case since I was used to camelCase. Since I didn't want to have countless warnings from the compiler, I used snake_case.
I agree, use what the language standards are and stay consistent!
I agree with that😁, we must follow the language conventions that we are working with. It's the best way to build consistent and clear code for a project.
I always try to adapt to each language's standard, because I believe it makes it easier to keep the codebase consistent (especially when working in a team).
I suppose I prefer camelCase or PascalCase (because of JS and C# standards), but I don't mind to adapt to a different standard as long as the codebase is consistent :)
Agreed!
Doesn’t matter to me as long as the codebase is consistent. If I truly had to pick one I would say camelCase just because that’s what I’ve used the most.
I agree; consistency is key!
Nice info! :)
Thanks!
Depends on the language and convention. Also use a linter to pick up any possible mistakes I may have made when working with a few languages at once.
Agreed!
I like snakecase / kebabcase more than upper / lower camelcase; but I decided to stick to a bigger standard, camelcase.
Interesting opinion!
I don't know why, but I tend to use camelCase in Javascript while using snake_case in python. It sounds kind of ironic where snakes have to do with python LOL.
That might be why Python decided to set snake_case as the standard 👀
I use both, I use camel case to name my functions and i use sanke case to name my variables , maybe it's wrong I need to learn more about the standards
Interesting approach!
A study shows that people find it easier to read "snake_case" than "camelCase"
ieeexplore.ieee.org/document/5521745
Interesting! Thanks for sharing!
I prefer camelCase.