Coupling – not the dating kind

I just watched Grand Unified Theory of Software Design by Jim Weirich on Vimeo and I found it quite insightful.

The main aim of his talk as I understand is to come up with an object way of recognizing and talking about good code design and more specifically code coupling. He referenced the idea of ‘connascence’ which basically means “things which change together”. There are different types of ‘connascence’ (I wonder when I’ll get bored of using quotes on that word).

Types of ‘connascence’

  1. name – method name and method call. When the name of a method changes you have to change the corresponding method calls. This is the weakest type of coupling and we refactor code in this direction.
  2. position – order specific process. Think of an array as opposed to a hash or collection of some sort – the latter is better. By using a collection/hash we reduce our coupling to ‘connascence of name’.
  3. meaning – variables mean arbitrary things that need to be understood to use them properly. Use constants instead.
  4. contranescene – namespace conflicts. Ever heard of jQuery.noConflict()? Make your variables play nice with each other by using namespaces.
  5. algorithm – duplication of algorithm in more than one place. I usually spot this very quickly.
  6. timing ie. race conditions. This happens when a function or process finishes sooner or later than it is expected to. In JavaScript callbacks are really useful.
  7. execution – order of execution matters.
  8. identity – objects have to be the same.

Coupling drives me crazy and I need to get better at reducing it. It’s scary when I want to change some code and I keep wondering if some function far away is going to break. (Tip: keep related functions close together). I found this mnemonic  SOLID helpful. Maybe I should write each letter on a finger. 😉


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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