One of the Best Bits of Programming Advice I ever Got
Years ago (early 1992), I attached myself to this crazy skunkworks project that was using this weird language called Smalltalk. “Object Oriented” was in its infancy as a “hot” item. High paid consultants. Lots of people laying claim to what this new object religion was all about. This was 5 years before Alan Kay would make the statement “I invented the term ‘Object Oriented Programming’ and this {Java and C++} is not what I had in mind.”
Shortly after hooking up with this whacky group with the whacky language, still confused about what the difference was between an instance variable, a class variable, and a class instance variable, I found myself in a training course taught by Russ Pencin, of ParcPlace. Russ would say something that I didn’t really appreciate at the time. Despite not understanding the point behind this sage advice, I endeavored to follow it. It would take years of experience and exposure to appreciate it’s value. The advice?
Don’t make objects that end with ‘er’.
That’s it. The OOP paradigm sprang to life amidst of a culture of what we called “procedural programming.” Now days we don’t talk so much about the comparison between the two paradigms. Probably in part because Object Oriented languages are now a dime a dozen. The OOP religion, in a multitude of flavors won out. Sadly, I often find myself echoing words I heard Adele Goldberg say around 2000: “Now days we have lots of Object Oriented Programming, but not so many Object Oriented Programmers”. If there was one piece of advice I would pass on to the hordes of would be Object Oriented Programmers, it would be the sage advice offered by Russ: “Don’t make objects that end with ‘er’.”
What’s in a name anyway? Why is this worth getting excited about? What I’ve
discovered over the years, is that the jst of OOP is that we bind behavior to data. As long as you haven’t joined in the Functional Monks in their Monasteries of Statelessness, programs are made of behavior and data. In classic structured/programming, we concentrate on behavior (verbs), and then figure out what data (nouns) we need to make it all work. In other words, we bind data to behavior. But in OOP, we make the locus of programs be the nouns, the data, and then we figure out what kind of behavior we can bind to them, and hope that the problems we hope to solve gel out of the emergent behaviors.
I recently posited to a colleague that in nearly every “er” object case, there was a better name for it. And that giving it a better name would tend to make the design more encapsulated, less spaghetti code, in short more object oriented. It’s not a hard and fast rule, but there are a lot of cases where it can improve things.
Take some sort of “Loader” for example. The focus here is on the unit of work it does. It’ll have lots of instance variables, lots of arguments, and pass lots of data around probably. Now instead replace that with a LoadRecord and a LoadStream. I’m reasonably confident you’ll end up with something that is more akin to what the original Founding Fathers of OOP had in mind. We want to create objects that describe what they are, and then bind behavior to them, rather than focus on what they do, and then figure out what data they’ll need to do that.
Some er’s that I’ve learned to avoid over the years:
Managers – Every time I see one of these, I cringe. People will usually tell me what it does, long before they can tell me what it is. Is it a registry? Fine call it a registry. Is it a history or a log? Call it that.