Archive

Archive for May, 2010

It’s Time to Ante Up and Go All In

May 31, 2010 Comments off

Mark Hollman and I are heading on an adventure in the city of sin.  What is this adventure you may be asking yourself, well it is the 2010 Better Software Conference and Agile Development Practices Conference in Las Vegas, Nevada June 6 – 11th. The conference is hosted by Software Quality Engineering, a consultancy firm that “offers education, publications, and real-world expertise to help you advance your software practices”. Our mission is to absorb as much information while in Vegas and make sure it doesn’t stay there.

I am very excited for a two day workshop that is new to this conference in 2010. I will be attending the Business Analyst Workshop on Monday/Tuesday. This workshop focuses on knowledge and skills that make a business analyst successful. The sessions are going to be highly interactive and provide me with practical takeaways I can use as soon as I am home in Saskatoon. I also will be attending a session on “Testing with Real Users—User Interaction and Beyond” by Seth Eliot and other sessions related to business analyst work. I hope to absorb all the information I possibly can and turn it into further blog posts and presentations for my coworkers at Point2.

Mark is excited for all of the sessions he will be attending and hopes that he can bring back tools and techniques that will help Point2 improve our process’s and collaborations between teams and departments.

Hopefully at the end of a tiring, but fun filled week of learning, networking and riding New York New York Roller Coaster, Mark and I can get some sleep. If you’re going to be attending the conference, or think there is something we should see or do while in Vegas – leave a comment! 🙂

“There’s just no quiet in Vegas” ~ Barry Manilow

By: Devon McGeary

Why Failing Tests Make Refactoring Safe

May 27, 2010 Comments off

I recently read an interesting blog post about why it’s ok not to write unit tests.

I disagree.

However, I believe the topic does deserve a proper rebuttal of some form, and I would like to try my hand.

You can find the full discussion at CodeQuirks.com but I’ve included the most important points here.

Why failing tests create safety.
Until recently I didn’t fully get the meaning of this idea.

The big problem I saw was that failing tests just got altered or deleted. How on earth does deleting or changing a failing test make the refactor easy? Couldn’t you have just refactored without the test?

The answer hit me like an untested jar-file.

When I change a piece of code and 3 tests fail, I can read those tests and know exactly what contracts I had violated. That doesn’t mean my change was wrong, but it does make it very clear what assumptions had previously been made about the system.

This empowers me to go into any areas that used those components, and modify them based on the new contract I am trying to put in place. I now know exactly how my alteration affects other areas of the system.

Categories: Point2 - Technical

Easy Java toString() methods using Apache commons-lang ToStringBuilder

May 21, 2010 2 comments

One of the disciplines I try to have while developing Java code is always overriding the default toString, equals, and hashCode methods. I have found that most of the modern IDE’s have a way to generate these methods. My IDE of choice, IntelliJ IDEA, does have this functionality but I find it’s implementations to be sub par. Here is an example of an IntelliJ generated toString method for a class…

@Override
public String toString() {
    return "Person{" +
        "name=" + name +
        ", age=" + age +
        '}';
}

My biggest problems with this implementation are:

  1. Hard-coded, static strings for class and field names makes the amazing refactoring features of IntelliJ less reliable.
  2. Not using StringBuilder makes this code harder to read and slightly more resource intensive.
  3. Only fields of this class can be used; all inherited fields, even protected ones, are not included.

This was just not good enough. I started to investigate if anyone had written some kind of library which could reflectively look at an Object and produce a complete (private and inherited fields included) and consistent toString representation. Sure enough, I discovered that one of the Apache Commons libraries provided exactly this functionality. The commons-lang project has a class called ToStringBuilder which has a static method on it that uses reflection to generate a string which contains a all of a classes fields. The string’s format is consistent and can be controlled by the ToStringStyle class which has several useful formats built-in and also lets to implement your own. You can now write any object’s toString method as follows:

@Override
public String toString() {
    return ToStringBuilder.reflectionToString(this);
}

If you are using maven as your project management tool, you can add the following dependency into your pom.xml file in order to be able to use the commons-lang library in your project.

<dependency>
  <groupId>commons-lang</groupId>
  <artifactId>commons-lang</artifactId>
  <version>2.5</version>
</dependency>

Normally I would try to avoid reflection in production code when possible due to it’s reported slower performance, however I find the only time I am actually using toString methods is usually in debugging or testing where speed is not my number one concern. If you don’t feel reflection is a good solution for you, the ToStringBuilder class does have several instance methods which follow the traditional ‘builder’ pattern which allows you to manually choose the fields which will be included in the string representation of your object. Here is example of that usage pattern:

public String toString() {
    return new ToStringBuilder(this).
        append("name", name).
        append("age", age).
        append("smoker", smoker).
        toString();
}

This usage does have some of the same problems as the original implementation like it requires the field identifiers to be static strings. This does however allow you to ensure a consistent format of the resulting string and it also has the ability to include the any super classes’ toString result using the appendSuper() method.

If you are using Eclipse or NetBeans, I understand there are very good plugins which can build very good toString representations but this functionality is unfortunately not enough for me to give up the refactoring support IntelliJ provides. The above solution would also help though if you have some developers on a team using different IDE; using a library to toString representations is better than IDE dependent tools since it maintains consistency between environments.

The ToStringBuilder class is just one of many useful utility classes provided by the commons-lang library and the commons-lang library is just one of the useful libraries provided by the Apache Commons project. Make sure to check it out anytime you find yourself writing some code and asking yourself “Hasn’t someone done this already?”

Setup Persistent Aliases & Macros in Windows Command Prompt (cmd.exe) using DOSKey

May 14, 2010 25 comments

Our development machines here at Point2 are not standardized; we have a mixture of Windows XP, 7, and Mac OSX/Unix computers. I find myself constantly switching back and forth between command prompt interfaces when pair programming. As a result, I catch myself using “ls” to list a directories contents regardless of what system I am on. I am currently using a Windows XP machine for my developer box and I wanted to setup an alias to the “ls” command to actually perform a “dir”. Here is how I accomplished it…

There is a command available in a Window’s shell that let’s you “alias” command to whatever you please: DOSKey. It allows you to create “macros” to execute one or more other commands with a custom name. If you open up a command prompt and type in the following, you will now be able to use “ls” to list the current directory’s contents.

DOSKEY ls=dir

It also handles command line arguments, either by index or as a collection using $1 – $2 or $* respectively. This allows you to do things perform a “dir” command every time you change directories. This example would be done with the following macro definition.

DOSKEY cd=cd $1$Tdir

This all sounds very simple and easy until you close your command prompt, open a new one, and realize all of these macros you defined earlier did not persist between instances. The DOSKey command does not save these alias automatically. The DOSKey command does support saving the “currently defined macros” to a file which will allow you to run a simple command in any new shell to load macros from any saved file. The problem is, I already forget to use “dir” instead of “ls” so I know for sure I will not remember to run a certain DOSKey command every time I open up a new command prompt. I needed something more automatic.

I investigated what options I have for running commands as part of every run of cmd.exe. I found out there is a command line argument, \K, that I can use on cmd.exe to tell it to run a ‘.cmd’ or ‘.bat’ file to run commands on startup. So you can run something like to following command to load a shell instance with the following command file being ran automatically.

cmd.exe /K C:\path\to\file.cmd

This allows you to add all of the commands you want into that file and have them run automatically for the command prompt you are about to open. In order to pass this argument, I created a shortcut to cmd.exe in my Quick Launch toolbar which I could modify and use exclusively for my command prompt instances. This can easily be done by going into your C:\WINDOWS\system32 directory, right-clicking on cmd.exe and selecting “Send to Desktop”. Right click on the newly created shortcut (on your desktop) and select “Properties”. On the Shortcut tab, you will find the “Target” field which you will have to modify to include the command line option. Here is what my configuration looks like:

The only other thing from my configuration worth mentioning is the “Start in” setting I have specified. The value “%HOMEDRIVE%%HOMEPATH%” will open the command prompt in your user’s home directory as opposed to the default which opens the new window in the system32 directory which usually isn’t very helpful.

My doskey.cmd file is also worth taking a look at. It only currently has a few alias for common Unix commands but it will give you a good idea of what kind of things are capable.

@echo off

DOSKEY ls=dir
DOSKEY cd=cd $1$Tdir
DOSKEY clear=cls

It is probably best to also include the “@echo off” at the top of your script too just so you don’t have to see the noise in the shell running your script. There are also a lot more powerful features to DOSKey that I have yet to experiment with but you can see how easy it is now to add permanent macros into your command prompt.

Another thing worth noting is that you should look at the other tabs in the cmd.exe Shortcut Properties window because it makes it easy to do things like increase the buffer size of text for the shell, change font sizes and color, as well configure the behavior of command history tracking. After tweaking with all these settings, here is my new custom, improved Command Prompt:

The only “gotcha” here is that you have to open command prompt window using the Shortcut but there are other tools available which will let you run Shortcuts a simple keystroke so this should not be an issue. I hope this makes every Window’s Command Prompt user’s life a little easier. 🙂

The Retrospective: A Key to Self-Organization

May 14, 2010 Comments off

This article is a summary of my opinions, expressed at CodeQuirks.com


One of the most interesting aspects of writing computer software, at least for me, has been the collaborative nature of what we do. I enjoy seeing the various ways in which a team can be organized, or organize itself, and the results of each of them. What makes software development effective, in the end, is an effective team that can deliver quality solutions to their customers in an efficient manner.

That’s why lately I’ve been absolutely fascinated with the affect agile practices have had on my team. The results have been absolutely amazing, but none of them come even close to comparing with the power of self-organization.

Self-organization has been one of the driving factors of the success of our team in the past few months, and I believe one of the most important aspects of our behaviour is our sprint retrospectives.

What does Self-Organization mean?

From Wikipedia:

Self-organization is a process of attraction and repulsion in which the internal organization of a system, normally an open system, increases in complexity without being guided or managed by an outside source. Self-organizing systems typically (but not always) display emergent properties.

Self-organization usually relies on four basic ingredients:

  1. Positive feedback
  2. Negative feedback
  3. Balance of exploitation and exploration
  4. Multiple interactions

But what does that really mean for a software team?

Well it implies a state of flux and constant change. It also implies that outside forces will eventually affect the team and influence its growth. However, these outside forces are not allowed to guide or manage the growth of the team. The team will, instead, react to the pressures of the outside world and adapt to them in order to operate more effectively. It really is a powerful statement, but how on earth does it work?

Positive Feedback/Negative Feedback

The purpose of a good retrospective is to look back at the previous sprint or iteration, and identify what things contributed to the successes and failures of the team. Often teams will identify many positive driving factors which helped them, as individuals, feel as if they were doing a good job. They will also identify negative factors which slowed them down, or made them feel as if they could have done better.

Balance of Exploration and Exploitation

Identifying what went wrong in a sprint is an excellent starting point, but that knowledge would be of little value if the team didn’t have ideas for how to fix the problems or prevent them from occurring in the future. Perhaps even more importantly, if the team isn’t aware of ways in which it can repeat the positive factors of the sprint, the benefit from them may quickly be lost.

Multiple Interactions

The primary artifacts of a successful retrospective are knowledge and action. The team is empowered with knowledge of what works, and what doesn’t. This way each team member can learn from the experiences of their teammates. The team takes action based on this new knowledge, in order to help become more effective and efficient.

Summary

While I go into a fuller analysis at my blog, I believe it is apparent that the sprint retrospective is one of the biggest keys to self-organization success. It provides many of the key properties a team requires in order to grow and achieve results. I can say from personal experience that the most important part of effective sprints, for me, has been effective retrospectives because they have allowed me to identify key areas for growth and learning. Perhaps one of the most important things you can do as a team, at least as a first effort, is figure out how to make these meetings flow smoothly and provide value effectively.

“I have but one lamp by which my feet are guided, and that is the lamp of experience. I know no way of judging of the future but by the past.” (Edward Gibbon)

Categories: Point2 - Technical

XmlBeanUtils

May 6, 2010 Comments off

Over the past couple of days I realized just how annoying it is to do simple data-lookups on arbitrary XML in Java.

The only two real options we seem to have are configuring XStream or JaxB, which is more hassle than it’s worth for simple data, or parsing the XML and manually traversing the DOM. Neither of these, honestly, seems like a sufficient easy solution to such a common problem.

That’s why I created, and open-sourced, XmlBeanUtils.

XmlBeanUtils is a simple library that allows you to load arbitrary XML into a Bean-like object for quick data access. For a more full description, read the full blog post.

(Please note: Apache Commons BeanUtils are required as a transitive dependency.)

Categories: Point2 - Technical