Archive for August, 2009

Software Patterns and the Dovetail Joint

Thursday, August 13th, 2009

I picked up my long-unread copy of Emergent Design by Scott L Brain.  I’m not too far in yet, but something he wrote about software patterns struck me in a way that hadn’t before.  He mentions that other professions all have their own patterns. Doctors, Lawyers and Carpenters, for example.  That made me think of the joints used by carpenters, like the dovetail example on the left[1].

Disclaimer: I’m no carpenter

Just like software patterns, carpentry joints aren’t a drop in solution.  Joints are a well understood carpentry pattern but they still must be used in context.  The type of wood being joined constrains the joint you can use, the desired appearance constrains which joints can be used, the use of the jointed pieces further constrains the choice of joint.  Further, the thickness of the wood will determine the size of the dovetails for example.  The constraints go on an on.

The difference between carpentry and software development is that the understanding of which joint to choose has been developed and refined by master craftsmen for thousands of years!  You can now buy laminate flooring that just clicks together - but it took the legacy of many, many craftsman hours to make that a possibility.

The take away for me is the re-enforcement of the truth: we’re still the software pioneers.  We’re still lashing bits of code together with rope, we can’t quite get a catalog of time-tested, tried and true joints.  We know enough to know there must be better ways of doing things, we just don’t have a clue of what they are yet.

Software development might just be about pioneer spirit, and anyone who tells you they’ve got it sorted is probably trying to sell snake oil to the prospectors.

[1] Image used under the terms of the Creative Commons Attribution 2.5 Licence - Author: Dumitru Rotari

Mmmmmm, coding…….

Sunday, August 9th, 2009

It’s not often that I get to do much coding these days.  Normally I wander around the office offering advice and guidance to others: aka, generally interfering (aaka, managing by walking around).  But today was a pleasant change, being a Saturday.  I remained cooped up and happy hacking away at a Circuit Breaker implementation inspired by Michael Nygard’s book Release It!  That book has enabled me to look deeper into the lives of Ops guys: the poor suckers who have to run the software that developers write, for years on end!  Release It! is a truly fabulous book and I recommend every single professional software developer to give it a good hard read (perhaps you could use the SQR3 technique).

Anywho, I got to code and I really enjoyed it.  I had written some of this code a while back, but without any tests.  I was allowed to do this because it was just a spike - it wasn’t intended to be production code.  But today I was to turn it into proper code.  Here’s what happened:

  1.  Removed extraneuous code I had added as an experiment into component transparency - exposing this as an JMX MBean.
  2. Removed other code that wasn’t going to be used in the first cut of this component.
  3. Create a JUnit 4 test case.
  4. Unit test #1: test that the delegate call works as expected - just what should happen when the circuit breaker is in the Closed state.
  5. Unit test #2: test that the circuit breaker trips when a single failure occurs (with the failure threshold set to 1).
  6. Refactor the test to make them more concise.
  7. Unit test #3 and #4.
  8. Refactor the tests, refactor, refactor.
  9.  #5, refactor, #6, refactor, #7….. continue testing various aspects of the circuit breaker.
  10.  Refactor the test cases and again and again.

I had previously written the code as a spike and tested informally using a browser within the webapp.  But now I wrote the unit tests to prove that I hadn’t coded any amusing bugs.  I wrote each of them so they would fail first, but I was testing existing code - not quite following the word of TDD but living the spirit.

But the thing I brought away from this was the amount of refactoring of the test case I did - I barely changed the existing code which was pair programmed originally.  The amount of test code refactoring reminded me of some work I had done previously about how a specific featureworked.  During my investigation I wrote a set of unit (missing) tests that got refactored and refactored and refactored until it made sense to someone who might care: not just a developer.  This took a good chunk of time to develop, but in the end I was able to publish a literal test as a Javadoc example that would make sense to your Grand Mother!

I did a similar job on the circuit breaker testing - pushing down on the test until it was concise and expressed my intent.  I squished and squashed until I had some really neat assert* statements that made sense for this component:

  • assertDelegateExceptionThrown
  • assertCircuitBreakerFailsFast
  • assertDelegateCallSucceeds

I had previously spent a chunk of time thinking about how this component should function and I reveled in the time I was forced to take in making the tests expressive.

I hope to add the ability to monitor the circuit breaker through JMX tomorrow.  This time it’s going to be TTD.

Mmmmmmm, coding…….

Quicksilver: jump to Jira issues

Saturday, August 8th, 2009

Currently I use that “Keyword” property of Firefox’s bookmarks to get me into the Jira projects I use at work quickly:

  • Bookmark an issue in Jira: http://jira.company.com/browse/PROJ1-53
  • Edit the new bookmark
  • Give it a sensible name - “browse jira”
  • Replace the Jira identifier with “%s”: http://jira.company.com/browse/%s
  • Give it a short keyword.  I normally use “j”.

Now you can simply type the following into Firefox’s location bar and jump straight to an issue: “j PROJ2-26″.

You still have to find Firefox and pop open a new tab and such.  I was wondering if I could side-step this and use Quicksilver to jump directly into an issue.  Note that this approach should work just fine with any other browser too.

Following the instructions over at coelomi’s blog I can now jump straight to a Jira issue with very little fuss.  http://coelomic.wordpress.com/2006/01/02/quicksilver-tips/

  • Enable the Web Search Quicksilver plugin.
  • Copy the Jira url.
  • Prepend the url with “qss-”.
  • Replace the issue id with three stars “***”.
  • Create a new trigger copying the url into the top box.
  • Ensure the next box says “Search For” and the next box is empty.
  • Assign a hot key for the trigger.

I now have the following triggers:

  • Ctrl-Command-j: access any Jira issue - I provide Quicksilver with the full issue id.
  • Ctrl-Command-r: access any Jira issue within a specific project - I provide Quicksilver only with the numeric part of the issue id - the project and the hyphen are hardcoded in the url.
  • Ctrl-Command-b: same as the one above but for a different project.
  • Ctrl-Command-g: A general google search.
  • I’ll be adding another to perform a search on our wiki too.

Learning to learn

Saturday, August 8th, 2009

I like to think that one of my strengths is my willingness to pro-actively learn new things.  Recently I have been trying to learn about learning by reading the excellent Pragmatic Thinking and Learning by Andy Hunt of The Pragmatic Programmer fame (which remains one of my favourite books of all time).

A lot of the content in PTL wasn’t that new to me, as I have previously read several of the books that Andy has read and references from the text.  That said, I definitely learned new things and deepened my understanding about certain areas.

Constant learning is definitely a incredibly valuable thing, I look for it in every potential new hire I interview.  But continually learning in the same habitual way may not be the optimal strategy.  If you apply the agile development approaches to how we learn it suggests that you should retrospect at what works, what doesn’t and that we should be prepared to try different things to see if they work better (rinse and repeat).

Though I’m not a novice at learning, I am a novice at learning using new tools and techniques: when was the last time you learned how to learn in a new way?  So how do I move froward from here?  According to the book, what I need is some novice/advanced beginner handrails to hold whilst I improve.  Different to the other books that I have read around this subject, PTL brings a consolidated set of next-steps in the context of the life of a software developer.

This is the initial list of things I am going to start:

  • Read more deliberately using the SQR3 technique, then blog about what I have learned.
    • Read PTL again, this time, read it deliberately.
    • Re-read Domain-Driven Design deliberately.
  • Increase my blogging frequency - hopefully doing more often will make me quicker.
  • Review my blog posts once in a while - do I still agree? what have I learned since?
  • Try mindmaps again having deepened my understanding about how they might help me learn/understand.
    • Redraw mindmaps every now and then - let some mental mushing happen - see what my brain has subconsciously come up with.

Ever more things will come up as I continually learn and continually learn to learn.  I’m still on that journey that started the best part of 33 years ago and one that I hope doesn’t stop for a very long time yet.

Objective-C having read a pocket reference

Saturday, August 8th, 2009

On the way back from a long-weekend on Vancouver Island we had a little time to kill whilst waiting for our ferry home.  There was a Chapters store nearby, so that was an easy mascre of half and hour.  After browsing for a while and noting possible future purchases I purchased Objective-C Pocket Reference.  At 122 small pages it was a quick read and covered he basics of Objective-C’s syntax and detailed various fundamental aspects of the Cocoa and GNUStep and the various differences betwen them.

I got from it pretty much what I was hoping: an easily digestible introduction into Objective-C.  I had previously read a bunch on the web, but I always find reading books, rather than reading a screen, to be far more effective for myself.  I had many different questions answered from an attempted iPhone coding session a few months ago.

I have been nudging some of the guys at work to start an Objective-C/iPhone/Mac programming study group. This book will be very useful for the novices in the group (myself included) to quickly look up the fundamentals and work through the syntax impedance as they try and push a new language into their Java brains - this was definitely a sticking point with the Erlang study group we had for a while.

In summary, a great, concise reference - just like the title suggests.  It appears that the reviewers on Amazon also agree.