This morning at Scotland on Rails Jim Weirich gave a fascinating talk covering a software development pattern called connascence_. His slides are available on Githubconnascence.
Connascence describes a kind of coupling within your code. Jim covered several forms:
In addition to the various forms of connascence he described two rules for dealing with connascence in your software.
His slides have good examples of each of these forms, but consider a quick example. If a method has several — say 4 or 5 — positional parameters, it has a high degree of connascence of position. Over time, if parameters have to be added, removed or just reordered, this code will prove to be brittle as any code that calls that method would also have to be updated. The situation can be improved by replacing those positional parameters with a single hash parameter. The hash keys introduce connascence of name but eliminate concern over position, decoupling the method defintion somewhat from the code that calls it.
I haven’t yet attended a talk by Jim that wasn’t enlightening (I got started with Ruby because of his “Ruby for Java Programmers” talk at OSCON 2005), and this talk was no different. Seeing these patterns isolated and explained helps me with the ongoing goal of achieving greater discipline as a software developer. Thanks, Jim.
© 2012 John Parker | Valid XHTML 1.0 Strict | Valid CSS 2.1