Another "one" principle -- The Most Important Design Guideline of Scott Meyers

June 03 · 5 mins read

We programmers tend to be lazy. We don’t want to know or remember all those many design principles or guidelines our masters are trying to teach us.

  • SOLID.
  • Favor composition over inheritance.
  • Separate those things that change from those that don’t.
  • All those design patterns (I only know a few :smile: I’m so lazy!).
  • etc.

Jonathan Boccara said the the principle that rules them all is

“respecting levels of abstraction”;

… which he said he first learned from Code Complete of Steve McConnell;

… which is related to what the authors of the GOOS book said on page 252:

“All code should emphasize ‘what’ it does over ‘how’, including test code.”

That is very easy to remember! Right?

Another “one” principle

I think I found another “one” principle or guideline that is easy to remember, and that any programmer can make sense of even if no one is going to explain it to him/her.

It is Scott Myers’ “Most Important Design Guideline”:

Make interfaces easy to use correctly and hard to use incorrectly.

Now, we can stop here and use our imaginations to come up with ideas on how to use that guideline in our code… But if we want to have some initial ideas on how to apply that guideline, then read on… :smile:

Scott Myers is the author of Effective Modern C++. I don’t really have that book. It only sounds familiar to me because it is one of John Sonmez’s ultimate list of programming books. Go and get it if you are interested.

And now…

:drum_roll: :drum_roll: (there's no drum roll!!!)


…here is the video of Scott Myers talking about his most important guideline:


:wavy_dash::wavy_dash:

And here is the summary of the suggested ways on how to get the results that that guideline is trying to achieve.

1. Adhere to the principle of least astonishment

  • Avoid gratuitous incompatibilities with the surrounding environment

  • Choose good names

  • Be consistent

2. Document interfaces before implementing them

Note that TDD, the discipline that Uncle Bob is promoting in his talks and in his blog, is also in here. Hmmm…

  • (46:20) proven way to discover interface problems: “If it is unpleasant to explain something, it is probably unpleasant to use it”

  • (47:00) Consistent with Test Driven Design (TDD) - which is involved with having the calling interface established before you actually write the implementation

3. Employ progressive disclosure (to prevent overwhelming the users of the interface with too many choices)

4. Introduce types to prevent common errors

  • Consider explicitly defining all possible values for the type

  • Avoid over-reliance on string

:wavy_dash::wavy_dash:

Scott Myers had also written about the guideline here.

Enjoy consuming those resources about that guideline! :yum:

More…

I think this guideline of Scott Myers is also related to “programming by wishful thinking”!

Well, who cares right? Everyone reading the masters knows that all these principles/guidelines are related to each other:

:wavy_dash::wavy_dash:

“The Single Responsibility and Open/Closed Principle are the Same”
– Michael Feathers

:wavy_dash::wavy_dash:

Scott Hanselman: “Well, … you’re looking at using all of the principles in tandem, together

Uncle Bob: “Yes. Well, if you’re following the SOLID principles what you’re really doing is managing dependencies. All of those principles is about managing the dependencies between modules.”

– from Hanselminutes 150 - Uncle Bob Martin: SOLID, this time with feeling – starting at about 32:30 in the podcast

:wavy_dash::wavy_dash:
Buy Me A Coffee