Jeff Atwood’s post on the evils of case sensitivity is the longest-lived blog post I’ve ever seen. He wrote it at the end of 2005, but people are still commenting now, a year and a half later. Wow!
His main point is that case sensitivity is evil, and that all programming languages should instead be case-insensitive but case-preserving. He argues that case sensitivity wastes time, and he’s never seen any evidence that case sensitivity saves time.
Well, here we go: I like Python’s case sensitivity, and I’ve rarely had a bug caused by it. Plus, I’m convinced case sensitivity saves time. How? In our code we do this sort of thing all the time:
user = User('ben')
Which creates a new instance of the
User class and fills it with ben’s data. Some people think this kind of naming is evil, but for us it’s clear, concise, and Pythonic. I mean, what are the alternatives?
usr = user('ben')
user = user_t('ben')
user = user_class('ben')
user = get_user('ben')
All icky, if you ask me. The last one’s the best, but then
get_user no longer makes much sense as a class name, such as when using class methods like
count = get_user.count().
The English language does something similar, except it has the opposite convention — a class is always lower case and an instance capitalised. For example, “Of all the cars I know, the Porsche 911 remains The Car.”
English has other case sensitivities as well:
- a Pole on a pole — what Daniel Baraniuk does
- a pole on a Pole — something you’d see in a circus
- a pole on a pole — to hang your flags on in Antarctica
- a Pole on the Pole — someone you’re likely to meet here
But back to programming. Programmers are “sensitive” people — sensitive enough to care about case. Non-geeks might be tempted to say we’re members of the Upper Case. But I believe it boils down to this:
Case sensitivity is great, but you need a convention.
In fact, you need good conventions whether you’re case-sensitive or not, but that’s another story.
It pays for your in-house convention to be similar to other people’s. And lets face it, in any given language there’s only one or two conventions to choose from. The one that’s worked for us is pretty simple:
- classes capitalised, instances lower, so
user = User('ben')
- short variable names lower, like
- longer variable names lowerCamelCase, like
We made those decisions early on. They’ve proved simple and efficient. And, strangely enough, we don’t have any of Jeff’s “I just spent the last hour…” horror stories to tell.
18 July 2007 by Ben 16 comments