Archive for July, 2007

The Apprentice

I am busy reading Software Craftmanship by Pete McBreen. The book introduces some very interesting concepts which differ from the concepts we are used to in normal software development.One of the main concepts of software craftmanship is the concept of apprenticeship. In craftmanship, like traditional blacksmiths, you would have a very experienced master who would transfer his knowledge to an apprentice. This apprentice will then learn by doing some basic tasks at first, and in working with the master, will be entrusted to doing more advanced tasks. This is in contrast to how we deliver developers in these modern times. Software developers would come out of university and would then be thrown into the deep end and left to fend for themselves.

I had an experience this week which indicated to me exactly how well the craftmanship idea could work with software development. At the moment we are working on a very large and complicated system. On Friday, we divided up into teams of two. Each team was expected to write a vertical slice of part of the system. I was paired with a much more experienced developer than myself. We were working together on only one machine and we discussed just about everything we did. This greatly increased my understanding of previous ‘dark’ parts of the system. I also learnt a few new tricks and also understand some of the technologies we are using much better now. And I am sure that the other more experienced developer also learnt some new things, even if it is only the different perspective I had on some of the topics.

I would really recommend this to any team. It might seam to be a waste of time, but I assure you that this exercise have possibly saved me a lot of headache that I would have had in the following weeks and in doing so, also saved me a lot of hours, if not days. I would also say that where I could previously only work on certain parts of the system, I am now competent to work and contribute to the whole system.

I think that this concept of apprenticeship could be very useful when new developers start working on a system or team. It does not only help them to understand the system better, but also helps them to be productive much quicker than usual. It also helps your team to understand each other better, increases communication between team members, and helps the team to function as a whole.

Software Craftmanship is a very good read and I would recommend you make some time, it might just change the way you think of software development.

GWTCompiler Memory

I am using IntelliJ IDEA (my IDE of choice) to work on some GWT stuff. I have been noticing some strange “Out of Memory” exceptions when compiling the GWT code into JavaScript, especially when the application starts to get ‘n bit bigger than your normal “Hello World” program. I am working on an application that, at the moment, contains about 40 very detailed forms and more or less 10 000 LoC. It is still very early in the development and thus, the application will grow some more over the next few months.IntelliJ IDEA 6+ by default includes a plugin named GWT Studio. This plugin allows you to specify only three settings at the moment (under Google Web Toolkit in your IDE Settings). You can specify the path to your GWT installation directory, the output style of the JavaScript, and you can choose to run the GWTCompiler when you build your application. I usually deselect this last option as it saves some time when you are running the application frequently (usually when debugging or experimenting with the style). You can then compile the code to JavaScript from the built-in browser by clicking on the “Compile/Browse” toolbar button.

As you may have noticed, the GWT Studio plugin does not provide settings for the GWTCompiler. This means that you cannot increase the memory for the GWTCompiler itself. You can, however, increase the amount of memory available to the JVM when running the application. To do this, enter the following as a “VM parameter” in your “Run/Debug Configurations”:

-Xmx512M

This will increase the memory to 512Mb when running the application and has worked well enough for me. We have also had some success by specifying the amount of memory available to the GWTCompiler by using Ant build scripts (I’ll leave that for another day).

If anyone else has other suggestions, please post them. I hope that in the near future, the GWT Studio plugin will provide more functionality, but as it is at the moment, it has already made my life a whole lot easier.

PS: If someone in the know is reading this, it would also be nice to be able to specify the output path for compiled JavaScript in the GWT settings.

No Java 5 – No Varargs!

The release of Java version 5 has provided us with some interesting and useful new ways to do things that would usually require a lot of effort, for example the new for-each loop and varargs.Varargs allows you to send a variable amount of arguments to a method. This is very useful when you would like to create a utility method to perform actions on objects or lists. There are many different ways in which to do this. The easiest would be to send the method a list of the objects and then loop through the list.

public void init() { 
    // assign the objects
    List list = new ArrayList();
    list.add(obj1);
    list.add(obj2);
    list.add(obj3);
    doSomething(list);
}

public void doSomething(List list) {
    for (int i = 0; i < list.size(); i++) {      
        // do something
    }
}

This method involves creating a new list, adding the object to the list, and then sending the list across to the method which then retrieves the objects from the list. In Java 5 this can be done with varargs and the new for each loop as follows:

public void init() {
    // assign the objects
    doSomething(obj1, obj2, obj3);
}

public void doSomething(Object … obj) {
    for (Object ob: obj) {
        // do something
    }
}

As you can see, the above method is much more simplified than the previous one. I have become used to this new method and the other new stuff in Java 5. Then I was asked to develop a demo in GWT (Google Web Toolkit). First-off I must say that I am very impressed by the GWT framework and what they are trying to achieve and the ways in which this makes developing web-based applications easier by allowing you to code it all in Java (personally I hate debugging JavaScript). There is one thing, you are only allowed to use Java syntax up to version 1.4. Great, there goes all the lovely new features of Java 5.

 

There is another way to pass a variable amount of arguments to a method by just using Java 1.4 syntax. That is by passing an array of objects. Take a look at the following example:

public void init() {
    // assign the objects
    doSomething(new Object[] {obj1, obj2, obj3});
}

public void doSomething(Object[] obj) {
    for (int i = 0; i < obj.length; i++) {
        // do something
    }
}

This provides the same way of doing it without using varargs. As varargs is basically an array which is being passed to the method as in this last example.

 

Let’s hope the Java 5 features will be implemented in GWT soon. But until then, this is how I will be implementing my own varargs.