When developing a larger codebase with several teams it can be challenging to hold everyone to the same standards. Sure coding standards can be forced, but some other things are much more difficult to force. In this blog post, we will take a look at how we can use the science of habit building to make sure developers do the right thing, or maybe even more important: do not do the wrong thing.

Developer experience

I’m a big fan of James Clear. The guy wrote Atomic Habits and has a pretty awesome blog. In one of those blog posts How to start new habits that actually stick, James describes the four stages of a habit. For full in-depth information, I recommend reading the article. In this post, we will focus on a subsection.

In programming, what makes developers take shortcuts? If we don’t take pressure and deadline stress into account. It is usually that the right thing to do is hard, and the shortcut is easy. Why write a migration for a data change if you can “just” click it in an interface? Sure it is much more error-prone, but also much faster!

In general, we want to make it easy to do the right thing, and hard to do the wrong thing. Let’s take a look in more depth.

Making it easy to do the right thing

There are four steps to making a habit stick.

  1. Make it obvious
  2. Make it attractive
  3. Make it easy
  4. Make it satisfying

Making it hard to do the wrong thing

We can invert these laws for the opposite side.

  1. Make it invisible
  2. Make it unattractive
  3. Make it difficult
  4. Make it unsatisfying

Real example

Years and Years ago we had a big MYSQL database with all our information in it. As it was pretty common 10-ish years ago, all developers had write access to the production database. In case we needed a quick fix or something. Over the years this grew into an anti-pattern. We noticed that there were features that were left unfinished because “we can just run a query by hand every day”, or that root causes where not identified. Since it was so easy to fix it by hand.

It took a developer with balls, and a lengthy discussion to get most of the devs on board. Of course, the frequent offenders did not agree.

We tackled this solution by:

  1. Revoking write access for everyone. (Made it invisible)
  2. Created a repository where migrations could be written that could only be executed once. (Made it difficult)
  3. Said migrations had to be reviewed by a member of an appointed group to make sure we did not misuse migrations for structural fixes. (Made it unsatisfying)

Not to our surprise, we found out there were a lot of things that were kept hidden by manual work. Having these migrations made it painfully awkward for everyone.

Before you go

Making sure people do the right thing is all about making it attractive and easy to do the right thing. And making it hard to do the wrong thing. You can use this science of habit building in more places like processes, developer experience, and more.

If you liked this post I recommend the following as well:

  1. How to create a culture where failing is acceptable
  2. Hanlon’s razor, a great tool to be more positive

Or you can subscribe to the newsletter.