Mmmmmm, coding…….

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

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

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

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.

Vi learnings

May 17th, 2009

Here are a few useful vi keystrokes I learned the other day (from colleagues and from the help system):

Searching without case-sensitivity – global switch:

:set ignorecase

Searching without case-sensitivity  – for a single pattern:

prefix the pattern with \c

Searching backwards:

? (rather than /)

Search again in the opposite direction:

N (rather than n)

Nothing too thrilling, but it makes using vi that little easier.

GTD: Keeping your Tasks/Todos in sync – Entourage, iCal, Todo, iPhone

February 21st, 2009

I’ve recently been thinking about my personal effectiveness and productivity.  I recently read through (most of) Dave Allan’s “Getting Things Done” and following a little Googling selected Entourage as my GTD centre.

Entourage was the easiest default choice for work.  I take my personal Mac to work and have to deal with Exchange: Entourage just works.  I have been having reasonable success with the Project Center and feel like I’m getting more things done (and the more important things too).

Not everything is great with my set up.  I have improved certain things mainly by adding some useful apple scripts to create tasks, events and messages from the current selection using shortcut keys.

Unfortunately, Entourage’s tasks don’t make it into to Exchange so they can be synced directly with my iPhone (like my calendar and mail).  This led me to sending myself emails to remind me to set up new tasks when processing my inbox.  So another googling and experimenting session followed.  Finally I came up with something that looks pretty promising.

Solution Overview:

  1. Use Entourage’s (2008) standard sync mechanism to get Entourage’s Calendar and Task information into iCal.
  2. Install Todo on my iPhone to show me my tasks on-the-go
  3. Use Appigo Sync to get the todo items in iCal into Todo and back.

Detailed steps:

  1. Step 1 is simple enough. In Entourage select the ‘Entourage -> Preferences’ menu.  Select ‘Sync Services’ and ensure the middle option is ticked ‘Synchronize events and tasks with iCal and .Mac’.
    Entourage PrefsOnce this is done, wait a couple of minutes for your data to appear in iCal (note the new ‘Entourage’ calendar that has been created).  Note that we aren’t really interested in the Calendar, but to do items are synced along with the calendar.
    iCal-Entourage
  2. Install Appigo Sync on your Mac (10.5+)
  3. Download ‘Todo’ from the iTunes Store for $9.99 (make sure it’s ‘Todo’ by Appagio, Inc.)
  4. Follow the following instructions to connect Todo to Appigo Sync: http://www.appigo.com/appigo-sync/faqs/connecting-todo

And you should be done – Entourage tasks should flow, via iCal, into Todo on your iPhone and back.  And it all looks pretty good at the moment.  Note that Appigo Sync only works over the same WiFi network that your Mac is on, but my iPhone is always with me – and my MBP isn’t really ever too far away.

The next thing is to see if Contexts and Projects can be made to play nicely from both ends.

Adding an auxiliary enchancer to OpenJPA

December 2nd, 2008

A while back I attempted to create a visualization of the relations that OpenJPA creates between the Java classes that it enhances – the intent was to help better understand a particularly intertwined persistent object graph and see if I couldn’t figure out why we were getting a few strange problems.

The initial approach I took was a hilarious trip into the land of sed, perl and graphviz.  It kinda looked like it worked, but didn’t actually :P

Time passed……more time passed……I learned more……more time passed…….and then I had the wacky notion of tying directly into the Enhancer that OpenJPA uses to create the persistence enabled classes.  I haven’t done the visualization yet, but this is what I learned about actually tying in an AuxiliaryEnhancer.

1. Create the AuxiliaryEnhancer

The following code is the minimal you will need.  Enter this and then compile – you will need OpenJPA and serp on your classpath.

package com.ij;

import org.apache.openjpa.enhance.PCEnhancer.AuxiliaryEnhancer;
import serp.bytecode.BCClass;
import serp.bytecode.BCMethod;
import org.apache.openjpa.meta.ClassMetaData;

public class Grapher implements AuxiliaryEnhancer {

    public void run(BCClass bc, ClassMetaData meta) {
        System.out.println("Running Enhancement");
    }

    public boolean skipEnhance(BCMethod m) {
         System.out.println("skipEnhance?");
         return false;
    }
}

2. Register the enhancer using jar based services

This is something I was only barely aware off – registering concrete implementations of services through jar file meta-data.

  • Create a file in a META-INF/services/ directory called org.apache.openjpa.enhance.PCEnhancer$AuxiliaryEnhancer
    • Note the dollar sign! That one caught me out for a while: I couldn’t decide whether the dot notation or the dollar notation should be used to reference the nested class.
  • This file should simply contain the fully qualified name of the Enhancer you wrote: com.ij.Grapher
  • Jar this directory and the class file up and you should end up with a jar listing like this
ivan-jensens-computer:jar ivanjensen$ jar tvf ../grapher.jar
     0 Tue Dec 02 21:56:42 PST 2008 META-INF/
    60 Tue Dec 02 21:56:42 PST 2008 META-INF/MANIFEST.MF
     0 Tue Dec 02 21:54:28 PST 2008 META-INF/services/
    16 Tue Dec 02 21:30:44 PST 2008 META-INF/services/org.apache.renamed.openjpa.enhance.PCEnhancer$AuxiliaryEnhancer
     0 Tue Dec 02 21:55:16 PST 2008 com/
     0 Tue Dec 02 21:55:38 PST 2008 com/ij/
   771 Tue Dec 02 21:55:38 PST 2008 com/ij/Grapher.class
   465 Tue Dec 02 21:54:46 PST 2008 com/ij/Grapher.java

3. Add the new jar file to the enhancer classpath

I did this by adding my jar file to the classpath element of my ant script – pretty simple.

4. Re-enhance your classes

Re-enhance your classes and you will see the System.out.println statements all over your console.

 [openjpac] skipEnhance?
 [openjpac] skipEnhance?
 [openjpac] Running Enhancement
 [openjpac] skipEnhance?
 [openjpac] skipEnhance?
 [openjpac] skipEnhance?
 [openjpac] skipEnhance?
 [openjpac] skipEnhance?
 [openjpac] skipEnhance?
 [openjpac] skipEnhance?

One thing I noticed about this: I had to delete my persistent classes and re-enhance, only then would the ‘run’ method be called.  The skipMethod is called whether I delete the classes or not.  I don’t know what that means yet, but I’m sure I am about to find out.

Notes:

I was actually using a patched version of OpenJpa 1.0.1 (for various, non-amusing, reasons), but the patches shouldn’t affect this tutorial.

Much Ado About Agile 2008

November 5th, 2008

I currently here at Much Ado About Agile 2008 – the conference organized by Agile Vancouver.

I managed to get in free by doing some volunteer work to set up the eCommerce system that sold the passes for conference. The software we used was the Elastic Path Commerce platform – I work for Elastic Path (who are also a sponsor of the conference).

I will be attempting to capture the sessions that I attend. So look out for my next post that will relay the enjoyable and thought-provoking keynote by Ken Schwaber, “Scrum and you mother-in-law”.

Geeky Learning-casts

September 28th, 2008

I’m constantly reading, watching or listening to stuff that makes me learn an I recently found the following very useful and timely for the work I’m doing at the moment (or in the near future).

Software Engineering Radio – fantastic podcast

August 24th, 2008

About two months ago I stumbled on the Software Engineering Radio podcast, and in my opinion it’s one of the best techy podcasts out there (anyone knows any different?).

There are currently 107 podcasts available and the 13 I’ve listened to (and listened to again) have been worth their virtual weight in gold.  There are a lot of interviews about many, many topics and the interviewees really know there stuff.

SE-Radio is an invaluable resource for the professional software developer.