The Acrid Stench of Polysemy

Posted: March 30th, 2008 | Author: Daniel Higginbotham | Filed under: Language, Programming, Rails | 1 Comment »

Recently, while working on designerpages.com, I wrote some smelly code. My task was to add the “change category” feature to the home page’s product wars, shown below. To do this, I needed a controller to receive the “change category” AJAX request, then set a session variable and return the code for refreshing the product war.

The stink arose from the name I chose for the controller, ProductWarsController. This might seem like an OK name, but it’s not, and after a short detour I’ll explain why.

Steven Pinker’s latest book, The Stuff of Thought: Language as a Window into Human Nature, introduced me to the term polysemy:

Polysemy refers a word’s having a number of distinct but related senses… the senses of a word are so tightly linked that it takes a linguist or an artificial intelligence researcher to spot the difference. here are some examples:

  • Chicken can refer to a kind of animal (Why did the chicken cross the road?) or a kind of meat (Try it, it tastes like chicken!).
  • Construction can refer to an event (The construction took nine months), a process (The construction was long and noisy), a result (The construction is on the next block), or a manner (The construction is shoddy).

While polysemy is fascinating and even entertaining1 when it occurs in the English language, it can easily lead to confusion in code. Code polysemy occurs when you use a name that appears consistent with your existing body of code, but whose meaning (behavior) actually differs in a subtle way. Users (you and other programmers) will expect your code to behave in one way, and when it doesn’t they’ll have to waste time figuring out what it actually does. Because the difference between expected and actual behavior is slight, and because the unexpected behavior is still related to the name you gave it, it’s easy to leave the mistake uncorrected.

Which brings me back to my stinky code. On Designer Pages, Product War has multiple, related meanings. It can refer to a model and it can refer to the actual Product War being displayed on the home page. The new controller ProductWarsController was meant to be related to the product war being displayed. However, under Rails conventions ProductWarsController should be related to actual Product War records. The resulting clash was confusing – the “update” action didn’t actually update a record, which is the expected behavior; rather, it changed which Product War would be used on the home page. What a disgusting hunk of effluvium.

The solution was to change the name ProductWarsController to ProductWarDisplayController. And now my code smells like roses.


1Pinker points out that polysemy also “arises when a word is used to refer to something that is merely associated with its usual reference… i.e. when one waitress tells another The ham sandwich wants his check.”


One Comment on “The Acrid Stench of Polysemy”

  1. 1 nomoreaccidents said at 4:17 pm on April 20th, 2010:

    Long time lurker, thought I would say hello! I really dont post much but thanks for the good times I have here. Love this place..

    When I was hurt in that motorcycle accident my life would be changed forever. Sadly that driver had no car insurance and I was going to be in pain for ever.

    This was not time for me to start and guess what to do. I had to find a good attorney to help me get what I needed. After all, my family was counting on me.

    How bad was it? I has bedridden for 6 months, I had to have constant care and my medical bills went through the roof!

    Fortunately, I found a good referral site to help me.

    I will post more later this afternoon to tell you more about what I have been going through.

    If you need an accident attorney try the guys at accident lawyers
    >


Leave a Reply