Building Software Cheat Sheet

10 12 2009

Building Software with a smile

I’ve been wanting to write this article for a while now, I use all my articles as personal notes, plus giving back to the community are something that counts in my book aswell. The article are about how we manage and build our software at work and the stuff im using for my private pet projects. It’s an ever evolving process, that will probably never stop. There’s always process’s that can be simplified. It’s a short article that you can use for getting a stack together quick. Enough chatter, onto the fun stuff πŸ™‚

Methodologies

We try to adhere under the ideas of people like Robert Martin (whom have summed up a lot of ideas of other people), go grab clean code you wont regret it. In short write code in a minimalistic readable way, remember to test it, care about your code and smile. Clean code really has summed it all up. Although there’s a lot of books on the topic’s of coding, testing etc. It’s my favorite. Oh and do not forget something like scrum.

Language

I’m not going to rant about why but we use Java, there’s several reasons but I have no deeper feelings about this topic, I havent looked enough into Ruby, Scala etc. to be a judge. Mostly that there’s so many things available for Java, however the same are the case for Grails, Rails etc. I just like static languages a bit more. However the topics in are not in depth about Java.

Building System

We are using Apache Maven 2, which has some really nice features like it’s convenience over configuration. There’s very good integration towards build servers and a huge list of plug-ins that’ll to the job for you. Just rememberer do it the maven way, and let the system work for you, do not fight it πŸ™‚ One side of Maven are testing, for that we are using a mixture of Junit4, Jmock and JBehave that ensures us maximum freedom and productivity.

Build Server

As for build server we are using Hudson, it’s simple and straight forward. It has great integration towards maven, I guess we could just as well have used Continuum but Hudson worked on first try Continuum did not. In Hudson we have three projects per Maven project, one for continuous integration and one for making a release and one for our metrics. The CI project are notified by our version system upon changes, then grabs the source and builds. The release project awaits when we are ready for a release, and then assigned build manager “clicks” build, awaits and downloads the finished release product, simple as that! The release process of course, checks out a fresh copy tags it in scm builds and releases/package the artifacts. I’ll write a bit about the metrics project below.

Metrics

Now what goes hand in hand with a build server are a metrics analyser like Sonar which actually are a bunch of subprojects packaged nicely together and presented in style. It’s really easy to add to any Maven project just have the sonar running and run mvn sonar:sonar and voila fresh metrics. Just remember sonar will only keep one set of metrics per day AFAIK.

Before I discovered Sonar I used a lot of time configuring Maven metric plugins. However Sonar does it all and easy, plus have a lot of features/plugins, like timeline hotspots and quick wins. Very nice all in all.

Version System

For scm we use Subversion, no real arguments here it works for me and I haven’t tried out any other scm. Most annoying thing though are that we are having some trouble using branches (svn 1.5 using eclipse/tortoise etc) otherwise not much to say. I’ve peeking a bit towards git, but haven’t had the time to go further.

Ticket System & Wiki

For Tickets/Defects/issues & Wiki we use trac. Reasons are that it’s simple and materialistic. Although sometimes to minimal, theres always a plugin that will just expand trac the way you want. Only thing that are bothersome is working with multiple trac sites. I’ve been eager to try redmine out, it seems like trac but can a bit more. So heres what im missing in trac:

  • Ticket dependencies
  • Multiple site support easy

IDE

We use Eclipse, mainly because it’s the one I’ve been using longest and one of our vendors has made a specific product based on eclipse. I’ve tried both subclipse and subversive, and can’t figure out what are best. None of them seems to be working optimally with branches. Only way to get a good diff when merging a branch are in svn command line :/ One note though we are limited to Eclipse 3.2 and plugins that support that. So it might be better in newer versions.

I’ve been told a couple of times by different people that idea, are better and actually will make you more productive. And now with the free community version I might give it a try.

Links

So following above, you should be set all the software mentioned in this article are free. Now go download and start making the world a better place. There’s a lot of projects out there waiting for you, either open source or for money. And just remember it’s better to try than not, some one once said it’s by our mistakes we learn πŸ™‚

Stuff we use:

Stuff that i’d like to investigate:

Ohh and if you have any comment’s feel free to write.





Cleaning Code Practically Episode 1

8 10 2009

Last Øredev I were at a presentation done by Robert Martin, author of the book Clean Code. I were really impressed by what his message where. So we are trying to follow his word at work and today a topic came up. So a colleague had this code:


public String getRequestString() throws MQException {
String request = "";
request += Helper.leftRightFilled(true, String.valueOf(getSessionNumberAndIncreaseIt()), '0', 3);
request += Helper.leftRightFilled(true, getVersion(), '0', 3);
request += Helper.leftRightFilled(true, getTransaction(), 'X', 4);
request += Helper.leftRightFilled(true, getLanguage(), 'X', 2);
request += Helper.leftRightFilled(true, getCallersPhoneNumber(), '0',16);
request += Helper.leftRightFilled(false, dynamicSettingMQ.getCustomerNumber(), ' ', 16);
request += Helper.leftRightFilled(true, String.valueOf(dynamicSettingMQ.getNumberOfUnsucceededCalls()), '0', 3);
return request;
}

I intermediately though that could be more readable, so I just pushed a lot into functions, and did a little to the helper class:

public String getRequestString() throws MQException {
String request = "";
request += createSessionNumberString();
request += createVersionString();
request += createTransactionString();
request += createLanguageString();
request += createCallersPhoneNumberString();
request += createCustomerNumberString();
request += createNumberOfUnsucceededCallsString();
return request;
}
protected String createCallersPhoneNumberString() throws MQException {
return Helper.leftRightFilled(true, getCallersPhoneNumber(), '0', 16);
}
protected String createCustomerNumberString() throws MQException {
return Helper.leftRightFilled(false, dynamicSettingMQ.getCustomerNumber(), ' ', 16);
}
protected String createLanguageString() throws MQException {
return Helper.leftRightFilled(true, getLanguage(), 'X', 2);
}
protected String createNumberOfUnsucceededCallsString() throws MQException {
return Helper.leftRightFilled(true, dynamicSettingMQ.getNumberOfUnsucceededCalls(), '0', 3);
}
protected String createSessionNumberString() throws MQException {
return Helper.leftRightFilled(true, getSessionNumberAndIncreaseIt(),'0', 3);
}
protected String createTransactionString() throws MQException {
return Helper.leftRightFilled(true, getTransaction(), 'X', 4);
}
protected String createVersionString() throws MQException {
return Helper.leftRightFilled(true, getVersion(), '0', 3);
}
}

At first the colleague thought it was nice, but then remembered he really needed a overview of locations used in the string manipulation. So a thing between the two are needed:

public String getRequestString() throws MQException {
String request = "";
request += createSessionNumberString('0', 3);
request += createVersionString('0', 3);
request += createTransactionString('X', 4);
request += createLanguageString('X', 2);
request += createCallersPhoneNumberString('0', 16);
request += createCustomerNumberString(' ', 16);
request += createNumberOfUnsucceededCallsString('0', 3);
return request;
}
protected String createCallersPhoneNumberString(char fillWith, int length) throws MQException {
return Helper.leftRightFilled(true, getCallersPhoneNumber(), fillWith,length);
}
protected String createCustomerNumberString(char fillWith, int length) throws MQException {
return Helper.leftRightFilled(false, dynamicSettingMQ.getCustomerNumber(), fillWith,length);
}
protected String createLanguageString(char fillWith, int length) throws MQException {
return Helper.leftRightFilled(true, getLanguage(), fillWith,length);
}
protected String createNumberOfUnsucceededCallsString(char fillWith, int length) throws MQException {
return Helper.leftRightFilled(true, dynamicSettingMQ.getNumberOfUnsucceededCalls(), fillWith,length);
}
protected String createSessionNumberString(char fillWith, int length) throws MQException {
return Helper.leftRightFilled(true, getSessionNumberAndIncreaseIt(),fillWith,length);
}
protected String createTransactionString(char fillWith, int length) throws MQException {
return Helper.leftRightFilled(true, getTransaction(), fillWith,length);
}
protected String createVersionString(char fillWith, int length) throws MQException {
return Helper.leftRightFilled(true, getVersion(), fillWith, length);
}

Im not satisfied, but not sure it can be done more clean? And if you are wondering about why we are doing all this string manipulation, we are working with some legacy MQ. If we split up the code without parameters as above we lose the quick overview.. But could the code be simplified even more please come with your suggestion..