Does your code speak business?

There are many books and manifestos or even books about those manifestos :-) the aim of which is to teach you how to be more efficient. They provide you with diverse recipes and tools to be more efficient as a person, as a developer but also as organizations.

All those writings also have another important thing in common; they all say that in order to be more efficient you constantly need to focus on delivering value or even steadily adding value.

I did a presentation during a Paris Software Craftsmanship Meetup, where I tried to define what exactly value is and the kind of things you could put in place (and things to avoid!) to bring it down to your code or even within your tests.

Here you go!

DDD is not architecture

While reviewing some résumés last week, my eyes were caught by this guy writing:

  • I’ve recently been focused on migrating to a DDD architecture

And some lines further:

  • Architecture redesign: Solution shifted first to MVC then DDD, multi-layered architecture implementation.

Apparently this guy tried to do some MVC but seemed not to be happy with it, so he decided to shift to DDD. This technique must certainly come from a secret chapter of Eric EvansDomain-Driven Design book that only this guy knows about! ;-)

Unfortunately this is not the first time I hear and see people confusing architecture and DDD.

A couple of weeks ago I went to a meetup where someone proposed to do a DDD Kata. I was quite enthusiast to participate and I started to imagine that we were going to do some Event Storming. Well, I must admit that I was quickly disappointed seeing the guy starting the kata by opening his favorite IDE. His idea was to do some code refactoring using DDD principles. To tell you the truth I was quite curious to see how he would manage to do so! The kata was similar to the Guilded Rose one; there was a lot of unreadable legacy code that you had to refactor to be able, at the end, to add a new feature without breaking the whole stuff. The guy quickly stated things like “as DDD tells us, let’s extract some interfaces so that we can put their implementations in another layer” Ouch! It took them some time (and a few remarks made by a couple of attendees) to realize that they were not doing any DDD at all.

So why do people keep on confusing DDD and architecture?

What I find as being the most likely explanation is that it’s due to the presence of the “design” term in Domain-Driven Design. But as Grady Booch says “All architecture is design, but not all design is architecture”.

DDD is not a technology; it’s a set of principles that will help you to deal with the complexity of an application domain by modeling it. DDD is focused on the domain and its logic where “Software architecture introduces structure and guidelines into a software system, leading to consistency and clarity” to quote Simon Brown.

But keep in mind that principles do impact your software architecture. Going with DDD will obviously lead you to choose the software architecture that will welcome it warmly. Architecture styles like Hexagonal Architecture or Onion Architecture will definitely help you to accomplish that as it will isolate the domain and avoid the business logic to be tightly coupled with any infrastructure related technology.

Should you go with DDD? Well, as it’s often the case, it depends! From my point of view it mainly depends on your domain complexity: the more complex it is the more you might benefit from DDD. But every choice comes with a cost; it will be up to you to evaluate the need and as Simon Brown says: “Principles are good, but make sure they’re realistic and don’t have a negative impact”!

The Ubiquitous Language

Project Manager: -"Hey, I found a bug on that page"
Developer: -"mmm, where exactly?"
PM: -"There, the market is not displayed correctly"
Dev: -"The what? Oh, you mean the football match name?"
PM: -"Yes..."
Dev: -"I see, I'm gonna warn the tester"
Tester: [BUG2435 Status: Reported] The event name is not displayed correctly on homepage

Here’s the kind of familiar example you might hear every week. This short dialog illustrates one of the most common problems we experience in software development: people do not share the same vocabulary. In this brief example the different characters have used 3 different ways to name things. It’s easy to imagine that business people have their own way to name that too, and members within the same development team could have different naming as well!
This might not look like something really important here, but think about a more complex system that deals with concepts ways more complicated than a single football match. What would happen if people do not share the same vocabulary?

I had a colleague that had a 2 columns sticky note he uses as reminder where he wrote on the left side the word his team is used to use and on the right side the corresponding business term. Well, this might help but wouldn’t be easier to share one common way to name things?
The worse thing I saw was that brilliant developer. He was that guy in the corner. The less he was dealing with business people and the less he was bothered by someone else, the more he was happy. This guy was so away from the reality that he was inventing his own terms! This kind of behavior is extreme of course, but it illustrates quite well the problem. If people don’t share the same vocabulary, the code will be very hard to read and understand thus maintenance costs will increase… just for a matter of vocabulary.

I recently participated in an Event Storming workshop animated by Jef Claes & Tom Janssens at NCrafts conference. First aim of Event Storming is to talk with a domain expert and try to find out all the events that occurs in the system (Event Storming has many other benefits, but that’s a bit off-topic, have a look at Alberto Brandolini‘s  blog here to learn more). We wrote the first events just after a short description of the subject by the expert. Those events were looking like “Shop Keeper Registered” or “Shop Keeper Account Updated”. After having talked a little bit more with the domain expert, it appears that the “Shop Keeper” term was not correct. The expert was using the “Partner” term instead. What if this was real life and that developers were keeping on using “Shop Keeper” instead of “Partner”? Let’s imagine the developer that needs to fix a bug on the Partner Registration process: he will search for any “partner” occurrence in the code and this will produce no result! He will need to struggle a bit to find the right place to fix the bug and then, he might add “Shop Keeper” = “Partner” on his 2 columns reminder sticky note ;-)

How could your code bring value if it doesn’t speak business?

Uncle Bob said that names in code “are the most powerful tool that programmers have to communicate with each other” and that “developers should use names to Reveal Their Intent and Avoid Disinformation“. Makes pretty much sense!

People often neglect the need to share the same vocabulary, they simply do not care.
Won’t you think that it would be easier for every person involved in a project to share a common way to name things?
What if the same vocabulary would be use from the business requirements to the software code or even the test code? Wouldn’t it ease the communication and the understanding of every one involved?

People always complain about communication between business guys and developers. Start by speaking the same language!

The Ubiquitous Language is the term used by Eric Evans in his Domain Driven Design book. The idea is to build a common language shared by everyone involved. As Martin Fowler said: “the language needs to be rigorous, since software doesn’t cope well with ambiguity” :-)

There are several ways to build the Ubiquitous Language, model storming and event storming workshop are one of them. But the successful ingredients of Getting-The-Ubiquitous-Language recipe are always almost the same:

  • find out the domains experts
  • put them in a room
  • ask a couple of colleague to join (another developer, a tester, …)
  • ask as much as you can about one specific part of the domain
  • put everything on sticky notes
  • it should not take more than 30mim
  • repeat until you think you’re done!

You don’t have to know about DDD in order to start Event Storming workshops.

One of the nice side effects of Event Storming session is that the more you’ll go deeper in details, the more you’ll see different part of the system naturally appear. You will get a pretty good idea of what components you’ll have to build (DDD speaking you’ll find out Bounded Context and Aggregate Root).
You will also be able to define your GivenWhenThens. As sticky notes are chained as events that must occur to get from one state to the other, it’s kinda easy to write your BDD styled tests! And that’s where having a tester in the loop is becoming interesting! Sounds like we have our 3 amigos meeting here ;-)

Hope all this gave you some ideas about things to try on your side in order to let you and your code speak business!

There are obviously other pretty good techniques to bring business and dev people close to each other but enough for now, I’ll have surely the opportunity to talk about this later in another post!