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’
- 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.
- 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’.
- meaning – variables mean arbitrary things that need to be understood to use them properly. Use constants instead.
- contranescene – namespace conflicts. Ever heard of jQuery.noConflict()? Make your variables play nice with each other by using namespaces.
- algorithm – duplication of algorithm in more than one place. I usually spot this very quickly.
- execution – order of execution matters.
- 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. 😉