The Name of Things

An entry about craftsmanship Publication date 2. December 2010 19:39

Take a look at the class you’re currently hacking away at in your project and ask yourself this: “If I showed another developer this class, and only this class on its own, would they understand what it does?”

Quite often, the answer is “no”. And that is a maintenance problem. Your next question then, should be: “How can I make the answer to that question ‘yes’?”

A great place to start is to take more care in how you name things. Give your class a name that clearly states what its responsibility is. Give your methods names that for commands clearly explain what action they will perform, and for queries what results they will return. Don’t forget to also think about the names of method parameters.

If something is difficult to name, consider the possibility that this is a symptom of poor design: Perhaps you’ve broken the single responsibility principle?

This may sound like trite advice, but developers are always in such a hurry. So slow down, spend a few seconds extra right now and make sure the code you write isn’t a sloppy mess, and you will be rewarded for it down the line where those few extra seconds spent could have saved you or your coworker half an hour of debugging because you misunderstood how a poorly named class/method functioned.

Currently rated 3.3 by 71 people

  • Currently 3.267606/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Powered by BlogEngine.NET 1.4.5.0

Welcome!

My name is Fredrik Kalseth, and this is my blog - thanks for visiting! I am fortunate enough to work with what I love for a living, and this blog is essentially the biproduct of that.

I work as a senior consultant for Capgemini, and am also an active participant in the Norwegian .NET community, as an avid attendee but also as a speaker (most recently at NNUG and MSDN Live).

As a developer, I have a wide circle of interest. My primary passion is for agile, test-driven development, with focus on best practices and clean code. That said, I also love to work on the frontend, especially with web development.

On Twitter? My handle is fkalseth. On LinkedIn? I`m there too.


Disclaimer

This is a personal blog; any opinions expressed here are my own and do not necessarily reflect those of my employer. All content herein is my own original creation, and as such is protected by copyright law. Unless otherwise stated, all source code posted on this blog is freely usable under the Microsoft Permissive License.

What Readers Talk About

Comment RSS