Cheese or Chaff?
Submitted by Antony Marcano on Tue, 08/01/2008 - 11:21.
agile | architecture
In a recent post, Jason Gorman highlights a common problem with code smells.
He is right.... code smells are a bit woolly and this leaves them open to interpretation. Because of this, like Jason, I've seen more time spent arguing whether the smell is present rather than whether or not the code should or should not be changed.
Jason's suggestion of making the smells more clearly specified - and in the specific example by defining whether getters and setters count as methods - makes complete sense (for what it's worth, I don't count getters and setters as methods when determining whether a class smells of 'data class'). I don't think, however, he need worry whether or not there are degrees of 'data-class-iness'. Smells are smells and not laws-and-commandments for a reason... A smell indicates that there probably is a problem but doesn't necessarily guarantee that there is a problem.
A while back, I'd gone on a trip and forgotten to clear out my fridge of anything that would go off. When I returned... I opened my fridge and out poured the most overpowering smell... I'd left some uncooked meat in there and it was now past its sell-by-date.
The smell was so bad it nearly ruined my childhood memories of one of my favourite cartoons as I thought... this must be how Pepe le Pew must have smelled...

But then the smell aroused another childhood memory... In Wimbledon Village, right by the bus stop where I'd catch the bus down to the train station... there was a shop that sold all varieties of cheeses... including the mouldy ones... you know the ones that (allegedly) are meant to be that way. The smell that came out of that shop was so bad (IMHO) that only the determined, stubborn and (I assume) unaffected would form a queue actually at the bus-stop.

The thing is... the shop always used to be busy... people actually went into the shop (I couldn't do it without a gas mask personally). These cheeses were meant to smell that way...
As I recalled this memory, it occurred to me that the smell coming from my fridge must be similar to the smell that comes out of the fridges of the cheese-loving customers of that little shop in Wimbledon Village (assuming you store such cheeses in the fridge).
Like food smells... code smells are, more often than not, an indication of a problem and/or the presence of waste. They tell you that you need to take a look at your code... like you would look in your fridge... to work out what you need to do about the smell. Most of the time you'll need to change something and/or throw something away... In rare cases, like rare cheeses, the thing emanating the smell, is the way it is meant to be... The important thing is that you have recognised the presence of the smell, investigated it and determined the best and most appropriate course of action. Most of the time, we'll see there is a good reason to get rid of the smell... sometimes (and only for very good reason) we'll decide to leave the smell because it is the way it needs to be.
More clearly defined code smells, as suggested by Jason, will help us focus our time on arguing over what to do about the smell rather than whether or not there is (or is not) a smell... but we need to remember that we should change the code not just because there is a smell but because the smell gets our attention after which our judgement and skill determines what we need to do about it.
Now, speaking of cheese... I wonder... how much cheese would it take to sink a battleship?....
He is right.... code smells are a bit woolly and this leaves them open to interpretation. Because of this, like Jason, I've seen more time spent arguing whether the smell is present rather than whether or not the code should or should not be changed.
Jason's suggestion of making the smells more clearly specified - and in the specific example by defining whether getters and setters count as methods - makes complete sense (for what it's worth, I don't count getters and setters as methods when determining whether a class smells of 'data class'). I don't think, however, he need worry whether or not there are degrees of 'data-class-iness'. Smells are smells and not laws-and-commandments for a reason... A smell indicates that there probably is a problem but doesn't necessarily guarantee that there is a problem.
A while back, I'd gone on a trip and forgotten to clear out my fridge of anything that would go off. When I returned... I opened my fridge and out poured the most overpowering smell... I'd left some uncooked meat in there and it was now past its sell-by-date.
The smell was so bad it nearly ruined my childhood memories of one of my favourite cartoons as I thought... this must be how Pepe le Pew must have smelled...

But then the smell aroused another childhood memory... In Wimbledon Village, right by the bus stop where I'd catch the bus down to the train station... there was a shop that sold all varieties of cheeses... including the mouldy ones... you know the ones that (allegedly) are meant to be that way. The smell that came out of that shop was so bad (IMHO) that only the determined, stubborn and (I assume) unaffected would form a queue actually at the bus-stop.

The thing is... the shop always used to be busy... people actually went into the shop (I couldn't do it without a gas mask personally). These cheeses were meant to smell that way...
As I recalled this memory, it occurred to me that the smell coming from my fridge must be similar to the smell that comes out of the fridges of the cheese-loving customers of that little shop in Wimbledon Village (assuming you store such cheeses in the fridge).
Like food smells... code smells are, more often than not, an indication of a problem and/or the presence of waste. They tell you that you need to take a look at your code... like you would look in your fridge... to work out what you need to do about the smell. Most of the time you'll need to change something and/or throw something away... In rare cases, like rare cheeses, the thing emanating the smell, is the way it is meant to be... The important thing is that you have recognised the presence of the smell, investigated it and determined the best and most appropriate course of action. Most of the time, we'll see there is a good reason to get rid of the smell... sometimes (and only for very good reason) we'll decide to leave the smell because it is the way it needs to be.
More clearly defined code smells, as suggested by Jason, will help us focus our time on arguing over what to do about the smell rather than whether or not there is (or is not) a smell... but we need to remember that we should change the code not just because there is a smell but because the smell gets our attention after which our judgement and skill determines what we need to do about it.
Now, speaking of cheese... I wonder... how much cheese would it take to sink a battleship?....
