Loose Coupling Considered Agile (2017-03-28)

Loose coupling. It’s where it’s at.

Let’s think about that.

Much of the time, when we think of writing code to do something in the simplest way possible, the first thing we do is think “I’ll write it like a script!”. So we set a few variables, make a couple of decisions and then grab a bunch of data and write a loop to do some stuff with it.

“Write a loop to do some stuff with it.”

The notion of the loop itself and whatever you’re doing with the data involved become intertwined. Separate things that are being done in the loop get intertwined. And inevitably, more than a little of the semantics of the code gets hidden. It’s often better to write what to do with one item and call that in a loop. By doing that, the concerns of looping (a ‘program domain’ idea) are separated – decoupled – from the semantic concerns of the result of the computation (a ‘solution domain’ idea). This decoupling make code easier to reason about and easier to change.

Try it! (smile)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s