a‡Y You are not a€oMr. Xa€¯
I keep coming across code like this (lifted, verbatim, from an OSS project I've been working with recently):$a = $num * $coeff + $_SANITIZED_GET['val'];
What, in the name of all that is good and just, is a€oa?a€¯ Or, for that matter, what are a€onuma€¯ and a€ocoeff?a€¯
Computer manufacturers, OS vendors, and programming tool developers have worked for decades to give us the ability to create identifiers of arbitrary length. Personally, I'd much rather see someReallyLongNameThatLooksALittleRidiculous than a function or variable name that won't tell me what it does at first sight.
The same goes for data. A a€o1a€¯ and a€o0a€¯ in a database don't tell you as much as a€oYesa€¯ or a€oNo,a€¯ which are just as localizable, indexable, and searchable. Enumerations, as far as I'm concerned, should be verbose unless there are very compelling space or performance requirements that say otherwise.
I know that there are many people who disagree with this approach, but their arguments tend to fall in the a€othat's the way I've been taught to do ita€¯ camp. The reality is, a numeric enumeration is just as arbitrary as a string-based one, but much harder for the human eye to make sense of-and we all know that, sooner or later, all data is looked at by a human eye. There are some circumstances in which performance and space constraints come into play, but otherwise the development tools at our disposal are mature enough to handle either type as easily as the other.
Besides, using numbers to identify non-numeric value is a domain violation. It used to be a necessity twenty years ago, but the vast majority of us work in environment that are well past that point. You wouldn't want to be called a€o492829,a€¯ right1?
So, if you are writing a book or teaching a course on programming, please teach your readers and students to write descriptive code. They'll be better for it, and we'll be grateful that you did.
- Yes, I know. You probably have some kind of social security number assigned to you by your government. But that's not your name-it's an index (that is, a numeric value) in a table that *contains* your name. Big difference. a†©