DEV Community

Henry Boisdequin
Henry Boisdequin

Posted on

Snake Case vs Camel Case

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 '_'")
Enter fullscreen mode Exit fullscreen mode

Javascript example (Javascript uses camel case):

const camelCase() => {
   console.log("Camel case is every word except for the first one is capitalized.")
}
Enter fullscreen mode Exit fullscreen mode

Let me know which one you like best!

Henry

📰 Newsletter
🐱 GitHub
🐦 Twitter

Top comments (23)

Collapse
 
iferminm profile image
Israel Fermín M.

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:

profile = UserProfile(user_data)
result = send_pending_notifications(profile)
handler = OperationResultHandler(result)
handler.handle_for_status_result()
Enter fullscreen mode Exit fullscreen mode

In this dummy code snippet, if we know it's following PEP8, we know that UserProfileand OperationResultHandler 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.

Collapse
 
somedood profile image
Basti Ortiz

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.

Collapse
 
hb profile image
Henry Boisdequin

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

Collapse
 
hb profile image
Henry Boisdequin

I agree, use what the language standards are and stay consistent!

Collapse
 
petroskoulianos profile image
Petros Koulianos

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.

Collapse
 
paulasantamaria profile image
Paula Santamaría

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 :)

Collapse
 
hb profile image
Henry Boisdequin

Agreed!

Collapse
 
cadams profile image
Chad Adams

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.

Collapse
 
hb profile image
Henry Boisdequin

I agree; consistency is key!

Collapse
 
dhren2019 profile image
Dhren

Nice info! :)

Collapse
 
hb profile image
Henry Boisdequin

Thanks!

Collapse
 
derekcrosson profile image
Derek Crosson

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.

Collapse
 
hb profile image
Henry Boisdequin

Agreed!

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

I like snakecase / kebabcase more than upper / lower camelcase; but I decided to stick to a bigger standard, camelcase.

Collapse
 
hb profile image
Henry Boisdequin

Interesting opinion!

Collapse
 
ironcladdev profile image
Conner Ow

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.

Collapse
 
hb profile image
Henry Boisdequin

That might be why Python decided to set snake_case as the standard 👀

Collapse
 
samuelnarciso28 profile image
Samuel Narciso

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

Collapse
 
hb profile image
Henry Boisdequin

Interesting approach!

Collapse
 
snsakib profile image
Syed Nazmus Sakib

A study shows that people find it easier to read "snake_case" than "camelCase"

ieeexplore.ieee.org/document/5521745

Collapse
 
hb profile image
Henry Boisdequin

Interesting! Thanks for sharing!

Collapse
 
martygo profile image
Martins Gouveia

I prefer camelCase.