Essay - Published: 2024.12.04 | camel-case | create | programming | snake-case | tech |
DISCLOSURE: If you buy through affiliate links, I may earn a small commission. (disclosures)
I stumbled upon a Twitter thread that made the best case for a variable name format I've yet seen.
The claim is that snake_case is better than camelCase and I kind of agree - here's why:
Before we dive into snake_case vs camelCase I wanted to make sure we're on the same page wrt what these formats mean.
Basically there are many common ways to format variable names - each with their own pros and cons:
Among others. Here we'll be comparing snake_case (common in langs like Python and Rust) against camelCase (common in langs like JavaScript and C#).
The thread author argues that snake_case is better than camelCase as it's easier to read:
Thus snake_case > camelCase.

I created a p5js sketch to visualize this difference:
(These numbers are pulled from the 2d web context and I believe are pixel units. This means the absolute number will be different depending on display but the ratio should remain similar.)
This is a pretty big jump in contrast with snake_case having ~3x higher contrast in word breaks which may make it easier to read / scan.
Another big benefit is that it cuts out bikeshedding around edge cases like how to capitalize an acronym.
Some examples:
In snake_case - every word is lowercase.
It should come as no surprise that there was some pushback to this argument.
The main counterarguments were:
_)These are all valid points and largely consistency in a codebase leads to better understandability long-term so shouldn't be discounted.
As always it depends and you have to weigh the tradeoffs for your own situation.
The goal really is around readability of code in order to make understanding it that much easier. snake_case seems to have an edge here but if you're mixing snake_case with other casing formats it can lead to harder to read code overall.
As a general rule:
Personally I've been writing Python professionally for several years and we tend to prefer snake_case over there. It was a bit of a switch from the camelCase I was used to before that but largely I've enjoyed it.
Going forward I will probably prefer snake_case for variable names but stick with PascalCase for classes / modules / properties as that seems more consistent overall.
If you want to play around with some variable name casing, check out my snake case vs camel case sketch on HAMY GAMES.
If you liked this post please leave a like, comment, and share w your network for the algorithm.
You might also like:
The best way to support my work is to like / comment / share for the algorithm and subscribe for future updates.