Back to the blog

The role under the name

A Java developer once asked which design patterns we use. The conversation since has settled on a simpler point. A pattern name is a shortcut, and the role under it is what a team shares.

Where We Left Off

Two pieces ago a Java developer asked which design patterns we use, and the answer turned into a description of how our front end spells those patterns without classes. Last time we wrote about the habit underneath. Someone names a shape in a code review, the name survives a few more uses, and it goes onto a short written list.

That piece started another round of conversation inside the team, and this one went somewhere we had not planned. Someone pointed out that the list of names is the smaller half of what we share. A new person can read the list in an afternoon and still not know where anything goes. What the team has in common is a sense of the role each piece plays, and the name is how we point at it.

The comparison that kept coming up was spoken language.

Every Language Has a Grammar

A spoken language gives each word a role in the sentence. Take "She draws the map." Put "has", "shares" or "prints" where "draws" is, and the sentence still stands. The slot expects a verb, and any verb does the job. A learner picks up that pattern in the first weeks. After that every new verb costs one word because the place it goes is already known.

Every language also has idioms, and an idiom works the other way round. In English, a job that turns out to be easy is "a piece of cake." Nobody learning the language can work that out from "piece" and "cake." Translated word for word, it is a remark about dessert.

An idiom is a shortcut. A few words stand in for a whole idea, and sometimes for several at once. Fluent speakers hear all of it without noticing.

What a learner needs in order to use one is modest. They need to know what the phrase does in the sentence: it describes a task, and it says the task was easy. The literal words are no help. With the role in hand, they can use the idiom the same day they hear it.

Programming Languages Work the Same Way

A Java developer, a JavaScript developer and a Python developer each arrive with a grammar and a stock of idioms. Here is one role spelled three ways. The job is to pick one behaviour out of a family by its key.

In Java it is an interface and the classes that implement it:

interface Sender { void send(Message m); }

Map<String, Sender> senders = Map.of(
  "email", new EmailSender(),
  "sms", new SmsSender()
);
senders.get(channel).send(message);

In Python it is a dictionary of functions:

senders = {"email": send_email, "sms": send_sms}
senders[channel](message)

The way we write it, it is a table with one row per type:

const senders = { email: sendEmail, sms: sendSms }
senders[channel](message)

Each one is the natural way to say it in its own language, and the role under all three is the same. A developer from any of the three reads the other two and recognises what is going on.

"Make that a registry" is our idiom for that role. Four words stand in for a table with one row per type, one function per row and one line that looks up the right row. The words are ours. The role belongs to anyone who has written software for a while.

What a New Person Needs First

This changed how we think about someone's first weeks. A new engineer needs the roles before the vocabulary: what holds the data, what decides, what draws the screen and what reacts when something changes. Those four questions have answers in every codebase, in every language. A person who can find the answers in ours is already useful.

The people who contribute most on our team are the ones who see what the structure is doing. Someone who sees the roles hears "registry" once, asks one question and has it for good. Vocabulary has little to do with it, and it follows soon enough.

The same holds in design work. A designer who knows what each part of a screen is for puts a new control in the right place on the first try. One part filters, one acts on a selection, one creates. What they call the parts makes no difference to the result.

Why We Draw the Shape First

People from different languages bring different idioms, and each one is a fair spelling of the same role. That is healthy. It is also where a team gets into trouble. Two people agree in a meeting, each hearing their own idiom, and find out in the code that they meant different things.

So before a change that crosses several pieces of the product, we draw it. Each piece goes on the drawing with the layer it sits in, what it takes in and what it puts on the screen. A drawing has no dialect. The Java developer and the JavaScript developer look at one picture, agree on the roles, and the names come after.

We learned the value of it the direct way. Not long ago we added a feature to four similar windows by writing the same sixty-odd lines into each of them. Every file compiled, and every step looked finished. The drawing, which we made at the end that time, showed in one glance what the code had hidden. The four windows shared a layer that nobody had built. We built the layer, the four copies became one, and the drawing has come first ever since.

A shape that already has a name still needs only a sentence in a review. A change with no name yet gets a drawing. That is what agreeing on a shape before building it means on an ordinary day.

Summary

  • A spoken language gives each word a role, and any verb fits the verb slot. An idiom is a shortcut that stands in for a whole idea.
  • A learner uses an idiom by knowing what it does in the sentence. The literal words are no help.
  • Programming languages work the same way. Java, Python and our own code each spell "pick one behaviour by its key" differently, and the role under the spelling is the same.
  • "Make that a registry" is one of our idioms. It stands for a table with one row per type, one function per row and one line that looks up the row.
  • A new engineer needs the roles first: what holds the data, what decides, what draws and what reacts. The vocabulary follows.
  • Before a change that crosses several pieces, we draw the structure. A drawing has no dialect, and it once showed us a missing layer that four compiling files had hidden.

Ask for a demo

Contact us. We walk through Aptli on the record types you name.