“primitive obsession” or “open secret”?

Yesterday Corey Haines posted yet another great video interview with JB Rainsberger. This time the topic under discussion was the Primitive Obsession code smell — what it is, how to recognise it, why it is a problem, what to do about it, and what you’ll see when you’ve fixed it.

I agree with JB — this is a difficult concept to communicate when teaching, and I think part of that comes from the name Primitive Obsession. In fact, after a vast amount of deliberation, Bill Wake and I proposed the alternative name Open Secret in our book Refactoring in Ruby. Our reasoning is that, as JB points out in the video, the essence of this smell is the fact that the lack of an encapsulating abstraction pushes knowledge and responsibilities and behaviour out into the open; whereas the representation of that knowledge should be a secret. It’s not so much the primitives that are the problem, but that they represent a domain abstraction — and that one chosen representation of that concept is visible to, and necessarily understood by, all and sundry.

Does that rename help explain this code smell?

Advertisements