Naming good is what Position?

Published

February 3, 2016

I want to drop in a quick note about variable and class naming, one of my favorite hobby horses.

I talked a little bit about choosing more completable names already. I think that is very important, and you would be well-served by paying attention to that bit.

Today let’s consider the serial position effect.

In any programming namespace, we’re going to come across some naming issues. Here is a non-comprehensive, non-exclusive list:

Is it wrong to have compound names? Probably not, and besides “wrong” is an uninteresting qualifier. Maybe better questions will help:
  • Is it helpful? 
  • s it only a coping mechanism for over-used namespaces? 
  • Is it a signal that our code is degrading? 
  • Is it a sign that we’re doing a good job? 
  • Is it a temporary state, that might be leading us toward more manageable code? 

Rather than answer ethical questions that we don’t have room for in this space, let’s consider instead that we have compound names, for better or worse.

What ordering should we use?

Serial position effect tells us that we will recall the first and last parts of the name most clearly. This has been illustrated in even smaller scale by silly facebook posts like this:
“If you can raed tihs, tehn you hvae a vrey rrae gfit. Olny sveen penecrt of plpoe are albe to usdtnernad tihs txet. You hvae an azimang bairn!”
Which of course, contains misinformation because just about anyone can read it if they look at it for a few seconds and can read English at all.

The interesting bit though, is that it is true that you don’t really struggle that much when the middles are scrambled because your brain doesn’t really latch onto the middles.

Maybe this is why it’s easier reading these really short paragraphs than the long ones above and the short bullet points instead of the longer ones.

It seems that if we are going to use long compound names, we might be better off if we:

Give it a shot today when you’re programming. It might lead you to more clear and easily-read names!