Buzz words that maybe matter — Law of Demeter

Di me’tr. The stressed vocal is E, just like E on ‘equal’.

11 a.m. o’clock sharp, same beverage and a week to go. Continuing last week series about every-time-spoken words in software engineering, today we’re talking about history behind Law of Demeter (also known as Principle of Least Knowledge).

Let’s start with a cool bingo card again: after all, cool and fun stuff is all this series is about.

“At Facebook they (…)” is missing, but everyone prefers square matrices, right?

disclaimer: this post is intended to have a recreational use: instead talking about what it is, we will bring the origins, who coined it, the implications along the 30-year hype and some cool stuff about Demeter. I bet you don’t have the idea who she is.


We are the 80's, and two guys in Northeastern University made a paper called “Assuring Good Style for Object-Oriented Programs”, lately published at IEE Software too. Pretty great name, isn’t it?

These guys were Professors Karl Lieberherr and Ian Holland, and they have worked inside Demeter, a research/project team that made several studies and tools about Adaptive and Aspect-Oriented Programming. Let’s remember that in late 80’s, Object Oriented Programming was rocket raising, against the procedural programming that showed to be way less readable and maintanable, and then, less profitable. Maybe we are feeling the same with functional programming today, but from different reasons (horizontal scalling, Moore’s Law stagnation and parallelism issues, etc).

In this paper, they describe the Law of Demeter: a code independent technique that was coined, refined and used by the team while building tools, and how it helps to keep code modular, encapsulated (sorry for buzzing), and then how every piece of software can be changed to have the Law satisfied.

Software engineering and agriculture relationship? Truly legen -wait for it- dary. (photo: Sonja Langford)

The university team were working on a hardware description language called Zeus, and now you know where we are going: in Greek mythology, Demeter and Zeus are both children of Cronus and Rhea, and also parents of Persephone. While working in a tool to simplify the language, they’ve searched for a name related to Zeus and Voila!, Demeter was chosen to be team and tool name. Remember that Demeter is the goddess of Agriculture and Distribution, and later the name was promoted as the idea to grow (remember, agriculture) software, not build software. Is brilliant how an idea (let’s reduce code duplication), a behavior (let’s try and follow the idea) and a code style (programming to get easier to follow the Law) became a thing itself, along the project. That’s the main point about using buzzwords: knowledge is great, but how it improves product, team or career? Just saying that X needs to be scalable means nothing: without knowing the real-world problem, the word itself is useless.

And indeed the former mentioned word has shown that works, because along this 30 years we are talking about it, and no, it’s not ~only~about avoiding two dots in same call.
Authors have later explained the Law in a brilliant way, expanding the idea and uses; just in case, combining it with the “Tell, don’t Ask” idea from Martin Fowler is a masterpiece when coding guided by OOP, in my opinion.


Thanks for reading the second post in series, and if you missed the first, how about taking a view on it? Next week we’re going to research about “broken windows theory”. Feedback are welcome, thanks :-)

edit 1: I’ve sent an email to Professor Karl asking permission for using his name in this post: he has answered me and credited the idea proposal for then PhD student Ian too.

References:
paper, IEE article, Professor Karl page, university project site

Luiz Fernando Nunes Marques

Written by

Software Engineer and amateur Tennis player. 5 min max stories about coding career.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade