A couple of weeks ago I discovered I had missed dozens of smells in a piece of code I thought I knew well. And today I discovered yet another smell in the same code, this time a really big one. What’s wrong with me?
I have a bunch of code, code that I wrote a while back. I revisited it a couple of weeks ago, because there was a smell in the the back of my mind and I wanted to scratch it. (Equating problems in code with bad smells has always struck me as an awkward metaphor, and somehow I can sense this post being more awkward than most.) However, the remedy for the smell that had been gnawing at me was large and complex, so before tackling it I thought I would look for anything simpler to tackle first. Low-hanging fruit to get my coding muscles warmed up. I put on my code reviewer’s hat and within a few minutes I had found around a dozen other smells. As is my wont, I marked them in the code with <SMELL> comments, and pretty soon there were long sections of the code with a comment on every line!
I had begun this exercise feeling fairly confident that the smell I knew about was pretty much the only smell in the code. But I came away wondering why I had missed all those others. One person, one set of knowledge about smells; two different hats, two very different perceptions of the code. Why?
I now believe this is a case, not of specific anosmia (the inability to detect certain smells, aka “smell blindness”), but of not listening to the code. I had one specific refactoring in mind, and my entire view of the code was distorted by the lens of that goal. But the code wanted something different; and many of these newly-discovered smells were clearly more serious and more urgent than mine. Note to self: let the code set the direction.
And so I thought that was that. I had a list of smells to tackle, and I sat down today to pick one and fix it. But as I was reading through, looking for a candidate, yet another smell hit me square between the eyes. This one wasn’t in the comments, because I hadn’t seen it during my review. And yet it was everywhere (I reckon 10-15% of the code is infected). What’s going on? Again, it can’t be anosmia, because I did detect it – albeit third time around. And I don’t believe this time I was blinded by any preconceived ideas, because I really had no idea what I would be tackling today.
So it must be some kind of layering effect: different smells are visible at different mental distances from the code. Today I was more distant, more detached, than on either previous occasion, and so perhaps I saw more. Maybe by placing the smell comments in the code, and out of my head, I had gained some detachment. Perhaps in doing that I had freed my mind from some of its preconceptions; and the two week break had then allowed it to see even more. When I had the goal smell in my mind it seemed like knowledge, but when I was able to devolve to the code itself, only then did the true situation become apparent.
I believe the moral of this story is that I’m a better programmer when I have Beginner’s Mind.
And here is the same post, with all those metaphors highlighted. (Let me know if I missed any?)
A couple of weeks ago I discovered I had missed dozens of smells in a piece of code I thought I knew well. And today I discovered yet another smell in the same code, this time a really big one. What’s wrong with me?
I have a bunch of code, code that I wrote a while back. I revisited it a couple of weeks ago, because there was a smell in the the back of my mind and I wanted to scratch it. (Equating problems in code with bad smells has always struck me as an awkward metaphor, and somehow I can sense this post being more awkward than most.) However, the remedy for the smell that had been gnawing at me was large and complex, so before tackling it I thought I would look for anything simpler to tackle first. Low-hanging fruit to get my coding muscles warmed up. I put on my code reviewer’s hat and within a few minutes I had found around a dozen other smells. As is my wont, I marked them in the code with <SMELL> comments, and pretty soon there were long sections of the code with a comment on every line!
I had begun this exercise feeling fairly confident that the smell I knew about was pretty much the only smell in the code. But I came away wondering why I had missed all those others. One person, one set of knowledge about smells; two different hats, two very different perceptions of the code. Why?
I now believe this is a case, not of specific anosmia (the inability to detect certain smells, aka “smell blindness“), but of not listening to the code. I had one specific refactoring in mind, and my entire view of the code was distorted by the lens of that goal. But the code wanted something different; and many of these newly-discovered smells were clearly more serious and more urgent than mine. Note to self: let the code set the direction.
And so I thought that was that. I had a list of smells to tackle, and I sat down today to pick one and fix it. But as I was reading through, looking for a candidate, yet another smell hit me square between the eyes. This one wasn’t in the comments, because I hadn’t seen it during my review. And yet it was everywhere (I reckon 10-15% of the code is infected). What’s going on? Again, it can’t be anosmia, because I did detect it – albeit third time around. And I don’t believe this time I was blinded by any preconceived ideas, because I really had no idea what I would be tackling today.
So it must be some kind of layering effect: different smells are visible at different mental distances from the code. Today I was more distant, more detached, than on either previous occasion, and so perhaps I saw more. Maybe by placing the smell comments in the code, and out of my head, I had gained some detachment. Perhaps in doing that I had freed my mind from some of its preconceptions; and the two week break had then allowed it to see even more. When I had the goal smell in my mind it seemed like knowledge, but when I was able to devolve to the code itself, only then did the true situation become apparent.
Fascinating thing, the Metaphorical Mind…
-
Top Posts
- hexagonal soup
- in-place editing in Rails 2.0
- people problems vs process problems
- setup and teardown for a ruby TestSuite
- reek, a code smells detector for ruby
- if...
- process improvement metrics - some questions
- the middle hexagon should be independent of the adapters
- gravity and software adaptability
- avoid boolean parameters
Category Cloud
Twitter
- @marcjohnson Yes, good to finally meet up! (Not insightful, just old) 1 hour ago
- Just spent a very enjoyable evening ranting on my usual hobby-horses with the @shruggers. Must get this side of the Pennines more often 10 hours ago
- Arrived Sheffield! Disappointed there's no snow; going straight back home 14 hours ago
- @ashleymoran @shruggers See you there :) 15 hours ago
- @marcjohnson I'm coming to ShRUG at Mojo; I feel like a walk tho, thanks all for the offers of a lift @andygoundry 15 hours ago
- Just got to Macc station in time for my train -- which I find is running 20 mins late! May miss the cnx to Sheffield :) 16 hours ago
- @Jagusti I'll check the dates tomorrow 16 hours ago
- @Jagusti Yeah, let's go for it :) 3 Mar looks good (although I don't have the weather forecast yet... 17 hours ago
2 Replies
Carnival of Agilists for June 22/07 – In Progress
People Over Process In one his all too infrequent posts Pete Behrens reminds us that is all about the people and not the practices: Scrum is Team-Driven Development. Johanna Rothman reminds us the Standup is about the team and not
[...] it hit me repeatedly between the eyes (can a smell do that)? Is this another manifestation of my anosmia? Am I smell-blind to Primitive Obsession? I don’t think [...]