And when you call it, you can call it Util

No. Actually you can’t call it Util*. You might think I’m a pain in the backside, nitpicking on issues like naming. I’m not.

Util, short for Utility is something useful. And it would probably be really useful if I could find it. But that’s the problem. You don’t always find it. When you’re working on a foreign codebase, things aren’t always as obvious as they seem. The only real thing that you can go by is the hope that other developers named things in sensible ways. Because otherwise you’re lost.

In fact, you’re not only lost, but you might even end up duplicating efforts, you know, you might end up writing that wretched helper method and put it in a class called FormatHelper as opposed to FormatUtil. And when Jack comes along, well he’ll just write his own and place it in FormatServices. Why? Cause the first time, we didn’t care too much about the name.

The only thing that I should rely on, the only thing I should be dependent on to understand the code, is the code. I shouldn’t have to bug a teammate to find out how something works or what a parameter means, or whether some routine exists or I should create it myself. We should leverage the language we all communicate in and understand and name things coherently.

Next time you’re figuring out what you should name a class, name it as what it does. And if you think that it does too much to describe it eloquently, then you’ll solve two problems in one go.

That’s why I’m so picky about naming. Because, despite what you think, it is not obvious until its obvious. And for you, the author, its always obvious. For me, it’s not.

* Util, Service, Helper, Manager, ….all of these are pretty much worthless…

6 thoughts on “And when you call it, you can call it Util

  1. Khalid Abuhakmeh

    I totally understand what your are saying, but even naming something does not garauntee you will find it. mvc is great in that i know exactly where to look for views (in most apps). If we would all adopt a convention, it would make life a lot easier

  2. Erik

    Yes, yes, yes! I fully agree about the importance of picking good names and the badness of calling something “utils” (or “helper” or “manager”). I’ve blogged about this in the past, but I’ll summarize quickly here. When classes are named this way, *anything* you put in them is categorically correct as long as it’s “useful” or “helpful”, which it will be, since the person writing it clearly has use for it.

    Adopting these naming conventions is an “anything goes” advertisement that invites technical debt due to poor organization and dependency management.

  3. Pingback: Sólo hay dos cosas complejas en computación « Blog de Francisco Velázquez

  4. Olaf Monien

    As long as I find recommendations in books (those about good programming practice) that say, that a longer method name is less easier to read than a short method name and thus recommend to keep names as short as possible (for readability!!), your dream will not come true 😉

  5. Scott D. Strader

    StringUtils, XMLUtils, etc. are perfect containers for simple, reusable code. When and if any group of those contained methods merit a class of their own (e.g. XMLAccountTransform) then they should be refactored appropriately. The magical util class is a step in the process of developing a project and stops you from over-engineering at the outset.

  6. Dmitri Nesteruk

    Utils are the worst, typically someone makes a static class full of stuff never to be discovered. Helper the same. Manager and service are completely different – typically these imply injection (especially Service), so at least it’s more obvious how to use them.

    Manager might also be a singleton. At least I’d go off looking for Manager.Instance before doing anything else.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s