DEV Community

Jethro Larson
Jethro Larson

Posted on • Edited on

3 1

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!

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more