DEV Community 👩‍💻👨‍💻

Jethro Larson
Jethro Larson

Posted on • Updated on

A Case for snake_case

The common naming convention in many languages I've used over the years has been camelCase. I've come to expect it and find other forms ugly or impractical. However, I only recently thought critically about it. It turns out there was a better alternative the whole time that works for more people in more places in more cases.

Let's start with the downsides of snake_case:

  • Looks blocky
  • Increases width of multi-word names
  • Uses more characters
  • Can be ambiguous when to capitalize letters

But the upsides are a bit more compelling IMO:

  • Easy to read by everyone, not just programmers. Related Study
  • Words can be capitalized based on their domain rather than to separate them. e.g. is_HTML_valid
  • Valid identifier in every practical programming language I'm aware of (unlike spit-case)
  • Doesn't cause problems when variable name needs to be put in case-insensitive contexts like urls or file names

The only reasons I can think of to not switch my style completely to snake_case are the divergence from standard styles of my language communities and the associated linters.

I'm willing to bet that the RustLang community had similar thoughts and that's why they took snake as the standard. Good on them!

Top comments (0)

"I made 10x faster JSON.stringify() functions, even type safe"

☝️ Must read for JS devs