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.