What I love is the repetition of the phrase
choosing the 'most convenient' place to put the
code, rather than where it actually makes sense
I have fallen victim to this. Rather than trudge through the code to make something explicit, we looked for the most convenient point of code insertion. Even while my partner and I talked about how it felt too implicit and a little "clever", we tried anyway hoping it would save us the cost of tracking down the places where the code was needed.
It turned out to be too clever by half (at least) and got us into a mess of indirect recursion and ugliness. Eventually we figured out how to have the compiler & tests tell us where the code was used so we could make changes explicit in their context, and this took us all of an hour maybe. It was a small cost, and left us with a more explicit answer.
Of course, it also meant that some code was now being called in seven or eight places instead of one. As we made this change, it didn't seem quite DRY enough, but it was explicit and clear and worked. Lacking the imagination and time to figure out how to make it more DRY without sacrificing the clarity, we left it. We may get to revisit it at some time, we may not. But the code is working, it is explicit, it expresses itself well, and it has tests. We could do worse.
I think Corey Haines nailed this one. Read his post. There is undeniably a siren's song calling us to put code in the most convenient (however implicity) places in the code instead of putting it where it makes the most sense. And, as Wally remarked in his response to "The C Word", sometimes people scatter clever code around the project instead of going through the inconvenience of building it a place to live.
Convenience already has a pejorative sense, due to the Dana Carvey's SNL "church lady" character. I suppose all day I'll hear his/her voice in my head saying "Isn't that conveeeeeeenient?" and sometimes "Isn't that special?"
Thanks for the kind words about my post. I love your reference to the church lady; I might just have to start saying 'isn't that convieneeent' more often.
ReplyDelete