Thursday, 5 July 2012

Adventures in legacy code: given a Map-based class, what do you think a method called getKey() should do?

Looking at some legacy code for a system that we're taking back from a
vendor. (Company has all these projects in-housing systems that used
to be outsourced) Rehost, port or rewrite?

Okay, so they created a class BundleMap that extends HashMap, and the
genius who wrote it added this incredible WTF "improvement":


/**
* Check if the key is present in the resource bundle
*
* @param key
* @return true if key is present
*/
public Boolean getKey(Object key) {
logger.debug("Returning value for key [" + key + "]");
if (super.containsKey(key)) {
return true;
}
return false;
}


AGAIN - WTF???

you already have a perfectly good method called containsKey() in
HashMap -- whatever the hell possessed you to rename it as getKey()??

No comments: