Snake Case vs Camel Case
Henry Boisdequin

Henry Boisdequin @hb

About: Programmer x Swimmer | React Dev, Machine Learning Enthusiast, Rustacean

Joined:
Oct 12, 2020

Snake Case vs Camel Case

Publish Date: Jan 15 '21
21 23

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

Comments 23 total

  • Chad Adams
    Chad AdamsJan 15, 2021

    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.

  • Pacharapol Withayasakpunt
    Pacharapol WithayasakpuntJan 15, 2021

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

  • Paula Santamaría
    Paula SantamaríaJan 15, 2021

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

  • Israel Fermín M.
    Israel Fermín M.Jan 15, 2021

    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.

    • Henry Boisdequin
      Henry BoisdequinJan 15, 2021

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

    • Basti Ortiz
      Basti OrtizJan 15, 2021

      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.

      • Henry Boisdequin
        Henry BoisdequinJan 15, 2021

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

    • Petros Koulianos
      Petros KoulianosJan 15, 2021

      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.

  • Dhren
    DhrenJan 15, 2021

    Nice info! :)

  • Martins Gouveia
    Martins GouveiaJan 15, 2021

    I prefer camelCase.

  • Derek Crosson
    Derek CrossonJan 15, 2021

    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.

  • Syed Nazmus Sakib
    Syed Nazmus SakibJan 15, 2021

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

    ieeexplore.ieee.org/document/5521745

  • IroncladDev
    IroncladDevJan 15, 2021

    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.

    • Henry Boisdequin
      Henry BoisdequinJan 15, 2021

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

  • Samuel Narciso
    Samuel NarcisoJan 15, 2021

    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

  • Jethro Larson
    Jethro LarsonNov 23, 2022

    I put up a similar post about this with my thoughts dev.to/jethrolarson/a-case-for-sna...

Add comment