One of the most difficult problems in programming is naming things.  Things such as variables, classes, methods, functions… everything needs a name and you, as the coder are responsible for providing it.

The reason this is tricky is that you are creating the name for *future* self.  *Current* self understands the code that you’re working on pretty well. I mean, you’re currently working on it!

But, if you’ve ever pulled out code from a few months ago and read it, you often get the sense that *past* self is not a great person.  He seems to have known what he was doing, but he’s not really letting *current* self in on that knowledge. His names maybe representing a mapping from the name to some understanding of the problem, but *current* self can’t figure it out.

The thing is that *past* self is a jerk.  I mean, he’s intentionally withholding information!  How inconsiderate.

Unfortunately *past* self can be a jerk even if it’s *past* self from a few minutes ago.  Except he’s not really a jerk, he just thought that *current* self would have a better memory than it turns out that he did.

One of my friends in school was working on a project where he wrote the comment:

//TODO: You will remember.

Which, when he read the comment the next day, he didn’t.

Knowledge can be slippery.  One of the things that brilliant programmers can do is that they are the best at “playing computer”.  This means that they can look at code and basically execute it in their mind and know what’s going on.  While all programming has an aspect of “playing computer”, unfortunately not all of us have been blessed with the ability to load entire programs into our working memory.  Most of us can load a few lines, maybe a small function’s worth of code at a time.  And if we have to keep mapping poor names to meaning as we do it, we’re just making it harder on ourselves.

The trick is to embed as much information as we can into the code, getting it “out of our head” into the code so that we can use our brains for the bigger problems at hand.

And that’s where naming comes in.  The biggest thing that we’re doing with naming is embedding our learning INTO the code.  Often we are mapping the name to understanding which involves cognitive load.  When we rename variables, classes and methods we are including information that we’ve learned in the code, reducing our cognitive load.  We can think of these as love notes to *future* self, telling him, “Hey, here’s what I figured out. You don’t have to keep it all in your head”.  Maybe *past* self won’t seem like such of a jerk.

Be kind to *future* self.  You’ll thank you when you’re him.

Share This