Over a million developers have joined DZone.

Weasel Words

· Java Zone

Learn more about the advantages of moving from a monolithic to microservices architecture.  Brought to you in partnership with IBM.

The other day I had to look into a project’s source code and shocked by the state it was in. I can, hand on heart, say I haven’t seen code like it for 10 years... which made it interesting.

Everyone, even the most inexperienced programmer seems to be able to look at code and figure out when it’s bad, after all there are obvious signs: for example it’s unintelligible, has lots of repetition through cut ‘n’ paste coding and its class and method names contain weasel words1

Weasel words turn up in both class and method names. Classes usually have weasel words appended to the end of their name, with the most common being Utils, Helper and Processor, for example: GeneralUtils, MiscellaneousUtils, PageHelper and XmlProcessor.

These Utils and Helpers are usually classes that are containers for disparate miscellaneous functions.

Then we move on to weasel word method names, a sure sign that the programmer who wrote the code didn’t understand what she2 was doing. Examples of weasel word method names are:

  • process(...)
  • manage(...)
  • parse(...)
  • fixup(...)

...with ‘process’ and ‘manage’ being my favourites.

Weasel Word class and method names like this are an example of the ‘Functional Decomposition’ anti-pattern, which has the following cause: lack of programmer experience and or ineptitude. The programmers just didn’t understand Object Orientation and have written functions that just happen to be in classes. Note that If you read various books and articles on this pattern, they usually list additional reasons such as bad specifications or architecture, but in my experience, this one’s usually down to us, the programmers - full stop3

The solution to this problem is simply refactoring. Take a look at the Weasels, itemise the methods in those Utils classes, move them to there own meaningful classes, add JUnit tests (if the code is that bad then I’ll put money on there being no unit tests). Remember that there isn’t a magic wand for this situation, you have to take the long view, refactoring a little at a time (story by story if you’re in the Agile world), so as not to break the product.

The cowboys who wrote the project I looked at probably left town on the last stage a long time ago. They either learn by experience and improve or simply go on making mess after mess leaving people like you and me to clear up...

1 I first saw the term Weasel Words when coined by Scott Adams in his Dilbert cartoon. He used it to refer to management speak, but is equally applicable to Software development.

2 You’ll notice I used the word she here. I’m not being misogynistic, I just didn’t want to assume that all programmers are male, although in my experience the overwhelming majority are. Besides, it seems quite trendy to refer to programmers as ‘she’ in technical books these days.

3‘Full Stop’ = English for ‘period’.


From http://www.captaindebug.com/2011/09/weasel-words.html

From Idea to Application gives you the architecture to quickly build, manage and run a range of applications (web, mobile, big data, new smart devices, etc.) on an open-standard, cloud-based platform. See why developers are using IBM Bluemix. Brought to you in partnership with IBM.


The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}