~pperalta

Thoughts on software development and other stuff

Archive for April, 2009

Code Review

with 3 comments

Yesterday I had the chief Coherence architect review some of my code before submitting it to Perforce. (No it wasn’t done by Cameron.) I actually look forward to them because I always learn something new. This time what stuck with me was the refactoring of a method and the before/after difference.

Here’s the before:

protected void configureAffinitySuffix()
    {
    String sJvmRoute = m_sConfiguredJvmRoute;
 
    if (sJvmRoute != null)
        {
        CacheFactory.log("jvmRoute set to '" + sJvmRoute + "' via configuration", 6);
        }
    else
        {
        sJvmRoute = getJvmRouteViaJmx();
        if (sJvmRoute == null)
            {
            m_sAffinitySuffix = "";
            CacheFactory.log("jvmRoute is not configured", 6);
            }
        }
 
    if (sJvmRoute != null)
        {
        CacheFactory.log("Configured affinity suffix: " + sJvmRoute, 4);
        m_sAffinitySuffix = SUFFIX_SEPARATOR + sJvmRoute;
        }
    }

Including blank lines, this is a 24 line method; and it isn’t very complex at all. Here is the newly refactored version:

protected void configureAffinitySuffix()
    {
    String sJvmRoute = m_sConfiguredJvmRoute;
    if (sJvmRoute == null)
        {
        sJvmRoute = getJvmRouteViaJmx();
        }
 
    if (sJvmRoute == null)
        {
        m_sAffinitySuffix = "";
        CacheFactory.log("The jvmRoute setting is not configured", 3);
        }
    else
        {
        m_sAffinitySuffix = SUFFIX_SEPARATOR + sJvmRoute;
        CacheFactory.log("Configured affinity suffix: " + sJvmRoute, 3);
        }
    }

The main differences are:

  • The new method is 19 lines, reduced from 24
  • All of the if statements are consistent; they’re all testing for a positive comparison
  • There are no nested blocks
  • The logging is more consistent, both in the ordering (the logging appears after the relevant line of code) and in the log level. There is also less logging so as to prevent the logs from filling up with noise.

All in all, we didn’t change the functionality of this method at all; however it is much cleaner and easier to follow. This is the attention to detail that IMHO is a significant factor in the quality of Coherence. (BTW, all submissions are peer reviewed before checking into source control.)

Written by Patrick Peralta

April 22nd, 2009 at 6:33 pm

Posted in Development

My Twitter account is broken

without comments

Anyone that follows me may have noticed no updates for the past few days. Somehow my account (http://twitter.com/patrickperalta) stopped working without any clue as to what could be the cause. Since I can’t log in to report a trouble ticket, I’ve sent an email to support at twitter.com, but I’m not holding my breath for a response anytime soon.

Strange thing is that I can still read updates from those that I’m following through Tweetie and TwitterFon, but no updates from me.

Written by Patrick Peralta

April 22nd, 2009 at 5:55 pm

Posted in Development

NY Coherence SIG on Thursday

without comments

This Thursday will be the next Coherence SIG in New York. Check out this new Coherence Blog by PM Craig Blitz for more details. I will be talking about POF (the Coherence platform neutral high performance serialization library), including some new features coming out in Coherence 3.5.

Written by Patrick Peralta

April 13th, 2009 at 9:49 pm