What’s in a name?

      7 Comments on What’s in a name?

I was recently asked about the Linq extension method FirstOrDefault and the question was put to me “where do I put the default?”

It made me smile, not because of the question – but that once again naming has required discussion. You’re told at an early stage in programming that naming is one of the most important parts of writing code – that there’s a responsibility that comes with it; most of the time that notion is immediately discarded by the young man or woman who thinks they understand the world.

It’s then the job of the next few years to hammer home the truth behind those words – to find naming both a source of confusion in the code you read and the stealer of time in the code you write yourself.

To someone who doesn’t know the default keyword, what else would the method do? The code clearly states you can specify a default. Doesn’t it?

And again it happened to me yesterday. I was discussing architecture of a sample which used the Repository Pattern. I thought I knew it used the repository pattern because the class had been prefixed with the word Repository.

The discussion continued, and it came about that a data access layer had yet to be added. I was baffled, why add a data layer to the data layer? And I said so – making points about the benefits of separation but not to add layers for the sake of it. I continued in this vein and walked away at the end of discussion feeling off. Something wasn’t right. (I owe the developers in question an apology for them having to listen to me rattle on)

The naming, that’s what wasn’t right, the business logic had been wrapped in a class called xxxRepository but it wasn’t the repository at all, naming had led me to assumption. The assumption was wrong. I know better than to let that nagging doubt persist as it normally means I messed up somewhere and I have yet to identify it.

I love the English language, I believe when it’s used in anger it’s a flowing and beautiful beast that can create and destroy worlds. As a father my daughter’s appreciation of literature is something I’m so pleased about – that the world is more open to her through her desire to read. But (I can’t, I refuse to use the Spiderman quote) you have to be careful with your words and understand that when you’re using smaller text – when the world is asking you to compress your communication and express yourself in fewer and fewer characters, when you have one or two words to clearly define the meaning behind something – those words are even more important, not less so.

Words are assumptions, and using them correctly will always make life easier.

7 thoughts on “What’s in a name?

  1. ProfessorVod

    “When you are completely happy with a method name you can finally put down the keyboard knowing your life as a developer is complete,” – Me, just now.

    Reply
    1. stoive Post author

      The flip side of that is the “Ronseal argument” – naming should be easy, because it should do exactly what it says on the tin. Not that I ever manage that.

      Reply
      1. ProfessorVod

        I find I get naming paranoia. The first name comes into my head is usually the best one, but then I think: what if something changes? What if the skies are not blue tomorrow? What if…what if…what if? The self-doubt that comes with being a developer can change a good name into a bad one, and vice-versa.

        Naming is simple yet difficult. With great power, comes massive electric shocks when you pee on the cables.

        Reply
  2. Roger Taylor

    Totally agree, naming is very important, badly named variables / classes give developers the wrong idea about what the class / variable is doing. Sad to say that people who have been coding for years don’t tend to think about others maintaining the code and name the variables poorly.

    Anyone who uses single letter variables just needs a slap imho.

    Reply
  3. Jamie Keeling

    One thing that bugs me with Resharper is its determination to change any instance of ‘ID’ to ‘Id’.

    Now I have always used ID in upper case for as long as I can remember, so it may be a genuine refactor that needs to happen. Either way, I should really change that rule at some point.

    Reply
    1. stoive Post author

      If the characters are at the end of a named item, then it’s ‘Id’ for me just for consistency. As a name in its own right? It’s a two-character abbreviation; that means I use caps.

      Reply
  4. Pingback: I can’t be right first time « I'm a Code Ninja

Leave a Reply

Your email address will not be published. Required fields are marked *