Naming Things is Hard

Good names are hard to come up with.

Some reasons we suck at naming:

  • We get in a hurry
  • Good names take careful thought
  • We are in a hurry

I see a theme.

Here are some rules of thumb I’ve found handy.

Don’t encrypt a variable name. For example, if you are tempted to call a “request id” hashValue because every request is assigned a unique hash, you have encrypted the meaning of the variable (and obfuscated it on top of that). Yeah, don’t do that.

Don’t make method names overly generic. For example, if you have a method that calculates the balance in an account, don’t call it “processAccount()“. Instead call it calculateBalance(). It’s much clearer what it does, and you’re less tempted to pollute it with other functionality that should be included elsewhere as you maintain and enhance the code (think of it as technical debt insurance).

Don’t abbreviate variable or method names. Ever. EVER. The abbreviation might make sense to you, today, as of this moment. But chances are six months from now, it will take you a second to figure out what the heck maxBalCalcd means (maximum calculated balance value? maximum balance calculation date? No, sorry, it’s “has the maximum calculated balance been reached”, thanks for playing). As sucky as we are at naming, we are even suckier at abbreviating those bad names. Your colleagues will thank you (okay, probably not, but it’s still a good idea).

Don’t play code golf with variable or method names. I’ve seen really smart developers use variables like e to hold the return value from a function call. And the description of the data does not even start with the letter e. But even if it did, it’s still a bad idea. It’s not obvious what it does, and just makes the code harder to read.

Do give something a name that exactly matches what it is does. If it’s a function or method, name it according to what it does (and if it’s name would be too long if you called it everything it does, then you need to refactor your design). If it’s a variable, name it according to the type of data it holds.

Do give loop variables simple names. Yes, this seems to fly in the face of what I’ve been saying, but I’m talking about throw-away variables that are used to loop through the items in a collection, for example. I like aa, bb, and cc. Some like i, j and k. But whatever you do, for god sakes, though, don’t call it loopVariable. That’s overkill.

Do use long names because they’re descriptive. I would much rather see a method called computeChecksumIfPossible() than compChksum().

Do learn the language of the business domain you’re writing code for, and name things accordingly. My favorite awful method name of all time: getAreaCode(). Looks innocent enough, right? Turns out the developer wanted the first three digits of the U.S. zip code. In the USA the term “area code” has a whole other meaning. I’m not making this up.

Hope you found these tips helpful. Please feel free to comment and add a few of your own.

Happy naming!


Make: Please Cancel My Subscription

I don’t know what has happened to Make Magazine over the years. When I received my first issue in 2004 I was very excited about the content, the projects (Mousebot!).

And this great editorial focus continued for years. Robots? Check. Circuit design? Check. Tesla coil? Van deGraff generator? Check. Check.

But something has happened in the past couple of years or so. The occasional article about “wearable blinking jewelry” (W.T.F?) has become the norm.

Back in the day, my Make subscription was a nice complement to my Nuts and Volts subscription (which has stayed true to its editorial focus since I’ve been a subscriber in 2005). Now, they are nothing alike.

O’Reilly, please cancel my subscription to Make. And good luck with wearable drone jewelry.


Breaking Bad

I began watching this show on a lark, and was hooked from the very first episode. I’ve watched them all (now multiple times, thanks to Netflix), and enjoy them very much. More than once I have asked myself why I am so drawn to this story of greed, obsession, lust, avarice, and raw humanity.

Walter White is a superbly intelligent individual. But he is also a deeply flawed human being. Several times throughout the show he could have walked away a rich man, and chose not to. Though it’s not completely clear why he walked away from Gray Matter (which, ironically, would have made him more millions – legitimately – than cooking meth every did), a careful study of the show reveals that Walter always feels that his genius is unappreciated. So he sold his shares, left Gray Matter with a huge resentment and “a couple of months’ rent”, and subsequently slid into mediocrity. That haunted him until his diagnosis.

From the beginning we see a man on a mission, and it takes him from hero, to killer, to criminal mastermind, and finally to fugitive. Like the man, the mission is deeply flawed. Never feeling fully appreciated, his obsession (matched only by his brother-in-law Hank’s obsession to catch the mysterious “Heisenberg”) leads him down a very dark path from which redemption is hopeless.

That said, Walter seems comfortable knowing that what he is doing is illegal. He seems to grow more at ease with the terrible things he has done, but never tries to justify it in terms of “free markets” or any other such nonsense, and does not try to disguise stealing from innocent (if perhaps greedy) people as “Capitalism at its finest.” In fact, he proudly declares more than once that the money he has acquired by cooking methamphetamine is money he “earned.”

Perhaps the lesson is this: greed in any form, leads to destruction. Period.

Or maybe the lesson is, when you have 1,000 gallons of methylamine and you can sell it for $15,000,000, take the deal.

That doesn’t make for very good TV though.

God and Guns: Vote GOP!

Hypocrisy irritates me. Speaking of hypocrisy, this is an election year, and the GOP primaries are in full swing. This week’s topic: morality!

While I believe Mr. Santorum is sincere when he spouts his brand of noise, claiming America’s moral decline is due to the number of unwed mothers, in the end, the GOP utopia is the World of “Bladerunner” where everything is privatized and corporations run the world (we are closer to this than you might think).

The GOP only cozies up to the religious right and the second amendment with their scare tactics to get the votes to bring that utopia to pass (after all they represent only 1%, which isn’t enough votes). The don’t give one tiny toot about morality.

Truth be told, the U.S. is a plutocracy; a system set up to (a) protect the wealthy and (b) make sure the system perpetuates itself. All this talk of morality is scare-noise meant to frighten the religious right into voting GOP.

And it works.

Facebook Addicting? That’s Ridiculous (I’m Totally Making That My Status)

I saw this article at ZDNet (they’ve been ON FIRE lately!) about Facebook and Twitter and how they’re more addictive than alcohol or nicotine. Can that be? It…

Sorry, had to check my twitter. What was I saying? Oh, yeah, Facebook and Twitter are addictive. I know for me that they hardly have any effect on me at all. For example,…

Oh, how funny. Somebody just posted the funniest link on my Facebook Wall. Where was I? Oh, yeah, Facebook. I don’t really check it all that often. I mean, I do have alerts sent directly to my Android phone (same for Twitter). But, really, it just doesn’t mean that much to ….

Wow, it looks like Lance Armstrong will be racing a 70.3 Ironman soon. Just saw a Tweet about it. What was I saying?

Oh, nevermind. I forget. Now if you’ll excuse me, I think I’ll check Twitter. It’s been, like, forever.


Deep Thoughts

There is no difference between strong and weak nuclear force, electromagnetic force and gravitational force. Force is force – and force is mass – and depends on the definition of “is”. At least, all this is true in three spatial dimensions, in which the speed of a photon in a vacuum is constant. Very exciting. There are also conditions under which, when time is constant and the speed of light varies that universes can be created and studied in an instant. In scenarios with multiple time dimensions, even more spatial dimensions are possible.

Our mathematics is too primitive to deal with the universe as it really is.

All structures are unstable. We have even been able to calculate the half-life of a proton (though it is longer than the currently speculated age of the experiment (universe)).

Eventually this experiment (universe) will end, the data will be collected, analyzed and the conclusion will be drawn: physics in three spatial dimensions with constant time is not sustainable. Everything eventually breaks down. The universe itself even “leaks” this truth through to its doomed inhabitants on occasion (to those who are open and listening). The ultimate truth is this: all are one.

How can it be that such primitive life can arrive at this marvelous conclusion?

What is Truth?

Saying there is one Truth is like saying there is only one kind of food to eat. Experience shows us that there are lots of foods to eat because we practice eating all the time. Unfortunately, we don’t practice spirituality much at all, so our experience is limited. In fact, I would argue that to the vast majority of people, practicing spirituality is an alien concept, which means we pretty much all suck at it. Is it any wonder then that there is so much division along religious lines in the world?

Why do we talk? Debate? Exchange ideas? I would argue that it is because an honest debate begins with the premise that I have an idea and you have an idea and we both might learn something from the exchange, which may ultimately shape our perception of “the truth.” We are both “right” in the sense that we bring something to the exchange we perceive as correct (or functional or valuable or whatever makes a belief “work”). But when we’re done, if our ego is not in control of the exchange, our positions may be forever altered for having had the exchange (vis-a-vis “Hey I didn’t see it like that. Cool.”). If our egos are in control, then you’re still wrong and I’m still right (or from your perspective I’m wrong and you’re right), and we’ve not done anything but try to convert each other to the “Truth.”

I never could get my head wrapped around any particular set of ideas and beliefs as the “Truth.” The whole idea never resonated with me. I mean, who says I’m “right” anyway? Me? What if I got my opinions from a book. Maybe a sacred book. Well, who says it’s sacred? If I believe it’s sacred, then it is. TO ME. But do I have the right to make you believe it, just because I do? See, here’s the absolute genius of belief systems that have this view of right and wrong. Their fundamental tenets (which must be spelled out in the sacred tome) must state that not only is everything written herein the Truth, but the fact that this sacred writing says so is proof enough, and furthermore (here’s the kicker) everybody who believes otherwise is (insert fate of “unbelievers” here). And to top it all off, you are never ever (ever) allowed to change your belief or you are weak. So this system sets itself up to be rigid and self-reinforcing.

What would possess me to think that just because I believe it, it’s the “Truth?” It may be MY Truth, but I have NO RIGHT to force it onto you. I would like to share it with you, but in doing so, your ideas will possibly influence my view and forever alter it.

NOW I’m practicing spirituality. The world is changing. People are beginning to see that it is no longer acceptable to force ideas about something so personal upon others.

Our collective human ego is dying.

Spiritual Software Development?

I wonder about this. It’s just something I’ve been thinking about. Can we bring our spirituality to our work? I think we can.

As a consultant, I feel ethically bound to tell my customers when they are heading in the wrong direction, and help guide them in the right direction (unfortunately, I don’t get much chance to advise them a priori). I am also ethically bound to fair billing practices.

But I think this is more than that. It has to do with what of ourselves we give to our work, rather than how we do our work. It’s a subtle but important difference. Just something I’ve been thinking about. Maybe I’ll write a book about it someday. And get on Oprah’s Book Club list.

Yeah, right.

Wow, Bing search results look just like Google search results

I can’t say I’m surprised. Microsoft’s new search engine, Bing, which is trying to compete with Google search, has results which look remarkably like google search results.

Does Bing use google search under the hood? It sure looks like it.

While Microsoft continues to try dominating, Google succeeds at innovating. I hope Bing doesn’t succeed (which, in Microsoft terms means to completely dominate all other offerings and leave us no choices), if for no other reason than I like having choices. And I choose to use google products. Not because I have no choice, but because they’re cool.

If Microsoft would try innovating instead of dominating, they might be able to survive going forward.


There is just something about an electric car that intrigues me. Probably my inner electronics geek coming out. But in any event, Tesla Motors has been given a huge grant to speed up production of their electric cars. Here’s a link to the InformationWeek article.

At some point, our dependence on fossil fuels is going to taper off. That day will come forcibly, or on our own terms. Things will go much smoother if we will accept the inevitability that we cannot continue to burn fossil fuels at the rate we are, and embrace alternative fuel sources. We’ll see.