Named after a variable

A strange thought (among others) has crossed my mind today, it totally made my day. Let me come to it.

So, I have been learning code refactoring lately at work, one of the things that happened during my blogging coma. We have been peer programming and doing code reviews to share coding best practices. It’s a very worthy and interesting exercise, even if it’s still a bit difficult to not consider your code like a personal “creation” (d-d-d-don’t touch it!). There is always a little fear when another consciousness reads your code and rewrites it, but it’s a good way to improve your coding skills quickly.

Anyway, doing the exercise I have been trying to write better code, and one of the most difficult things is to find the right names for the variables because you want an “expressive” code. The best practices guru who guides us says that you can tell if a code is good if you know what the code is doing right from the names of the variables and functions. True. The names are really not a detail. Writing code is indeed really “writing”. That’s the part that usually takes me a long time to figure out, and what I’m always rewriting. How to name the variables nicely from the start?

First I thought, gee it’s more challenging than naming a baby, I mean there is only one baby to name usually, and the name doesn’t have to be expressive, it can just be “Roberta”. Then I thought, cool, so then why don’t I name my variables the same way? $Roberta = function(){};  I totally could. I mean among devs we already refer to functions or modules as people. In the office you can hear stuff flying around like:

What?!! But why doesn’t he like that? He doesn’t even go there!! See: blank page.

Honestly, I don’t know what he’s doing, it’s like he goes here, and then he goes there, but he never goes here;
WHY ?!!!

What are you working on?
Yes, but hook_update is not gonna like that, you have to pass it as a reference
Houu that little bastard! Actually, he was expecting a string!!!

But then, I thought, wow indeed the names of variables are so much more complex than people’s names, I mean they can have special characters like “_” or “$”, “-“, a lot of possibilities!

So finally, here is my glorious thought: what if we named people like variables? You could get very creative. “Hi, my name is $john, with a silent $ and a minuscule, be careful it’s certainly not _john or _jOhn, someone already made the mistake :)”. I mean, have you really never thought of putting an underscore in your name? or make it in one string like indianaJones, or even what about all the other characters? What about something like James\Bond, “my name is Bond, James Bond, with an anti-slash” or James_Bond? “Bond, James Bond, with an underscore”, sounds good! Oook, it’s late, I’d better go to sleep now.

Actually we kind of already do that but we call it a handle, not a name, what if it became a part of your name? First name, middle name, family name, handle name? Henry Walton Indiana Jones $_indy. Anyway, now I manage to find a variable’s name quickly without over-thinking its destiny, but I still find it funny that you could name someone hook_update. Good night hook_update! Or should I just call you hook?

  • My goodness, I am re-reading this article exactly 5 years later! and I think I am insane! LOL.