JAOO - Day 6

October 12th, 2006

Well, I’m a little late for my report for day 6 (loads of work waiting for me in the office), but here it is.
Day 6 was Alistair Cockburn on his “Crystal Clear” methodology. He told us about the problems we are facing and how Crystal Clear tackles them. In the afternoon we did some, well let’s call it “practical games”, excercising some techniques on a little game-project.
Then it was off to the airport for me - I had a very tight schedule for my three flights home. As the first flight was already delayed by 15 minutes, this meant I had to run through Copenhagen airport to catch the next flight - waiting for 10 minutes, because this one was also late.
I also managed to get my last plane, so I arrived in Linz (Home, sweet home!) at 23:00. My luggage was not so lucky, it arrived at 11:30 the next day - boy, was I glad that I didn’t have my keys in the suitcase ;-)
So good bye, JAOO - see you again next year!

JAOO - Day 5

October 5th, 2006

This is Day 5 of the JAOO. The conference ended yesterday and there are just two days of tutorials left.
First I chose to see Angelika Langer on “New Features in J2SE 5.0″ (also to support my learning for the SCJP certification). Learned some new things, found out that I had already understood some things right.
The second was “EJB 3 Persistence with OpenJPA” by Patrick Linskey and David Ezzio, which was a very good introduction into JPA (and a little EJB 3) and some additional information on the OpenJPA implementation. Same here: learned some new things, found out that I had already understood some things right. Still a great presentation (they also showed some running code samples).
And another discovery: up to today, I thought I was the only guy on the conference coming from Austria, until I met two guys from Vienna (it felt really strange directly talking to a person in the oh-so-familiar austrian dialect again). So the Austrian-Count is up to 3.
Shot some photos in the center, got the bus (Yes again!) - unfortunately the wrong one (D’oh!). Funny thing was, I noticed this when I got off the bus (at the station where I thought I would have to) and the place just didn’t look as I had expected. But I had luck this time: as I looked around I noticed that I was only some hundred meters away from my hotel.
Seems like these kind of things always happen to me when I think about something completely different while trying to do some compilicated task (like getting on the bus).
Well, I’m back in the hotel, so after The Simpsons (with danish subtitles) I might as well have another 7-Euro beer.

JAOO - Day 4

October 5th, 2006

This is day 4 at JAOO, which for me was the track “Back to the Future” hosted by the Practical Programmer Dave Thomas. The core idea of this track was to show up some concepts of “old” or not-so-mainstream programming languages, if they worked out the way they were supposed to, and if not, why not (was it because it was just a miserable concept or did some environmental factors prevent it from succeeding).
The first talk was another one by Guy Steele, this time on the history of Scheme (and a little LISP lesson) - “WOW!” again. It was followed by a talk on Haskell by Erik Meijer, a talk on Colored Petri Nets (an extension to the Petri Net model) and a talk about SIMULA and BETA.
The great final of the conference (the next two days are “only” tutorials) was a panel discussion about what will programming be in 2016, with Guy Steele, Ole Lehrmann Madsen, Steve Vinoski, Kevlin Henney and Erik Meijer, hosted by Dave Thomas.
The key points were that programming languages will have to provide better abstractions (especially for concurrency), DSLs will take an important role (as a special kind of abstraction), current main-stream languages will evolve (and/or die - be serious, who really thinks that he’ll be doing Java until he retires? On the other hand, as someone noted, there is so much Java code around, some people may have the (questionable) “opportunity” to maintain Java legacy code for the rest of their lives) and of course new languages will step on the scene (or take it over).
That was it for day 4. Picked up something to eat (a salmon sandwich after which I felt a little strange - hope in my case the salmon had nothing to do with salmonella), got the bus (yes!) and enjoyed two beers in the hotel (there go another 14 Euro).

JAOO - Day 3

October 3rd, 2006

I started day 3 with no great expectations at all (maybe because I was still a little sleepy from yesterday’s party).
It was supposed to start with Guy Steele on “The Soul of a New Programming Language”. I had heard of this Guy, so I thought it would be a good talk.
After the talk I had only one word left for it: WOW!. The talk was about Fortress, a brand new language Sun is designing especially for scientific purposes. It’s supposed to be “the new Fortran” with really phantastic features: a language that supports mathematical notations, contracts (against which the implementation is automatically unit-tested), operator overloading (he made a good point why it was going to be better than C++ operator overloading), transactional distributed memory, built-in notion about other nodes in the computation cluster (so loops are automagically distributed to multiple nodes) and much, much more. After this talk I needed a long break to let this all settle down … WOW!
Then I saw the end of Eberhard Wolff’s introductory talk to the Enterprise Performance track, one guy from Tangosol and one from BEA talking about performant Java persistence (unfortunately I already knew their slides from somewhere on the web) and then Kirk Pepperdine on Performance Anti-Patterns. Angelika Langer’s talk on Micro-Benchmarking in Java revealed some interesting details of the JVM and the Hotspot compiler (she still only got a green-minus from me). And Andre Bondi talked about Performance Engineering on a project of his (how to measure performance, how to interpret the results and how to tackle problems).
After the conference, and after waiting for the bus for ’bout an hour (there was some demonstration going on, so maybe this was the reason), I decided I needed something to eat. Denmark? The sea? Fresh fish? Sushi! So I went to a super market and bought what turned out to be one big roll of rice, filled(?) with this algae stuff (not the kind Alistair Cockburn was talking about yesterday) and with some pieces of raw fish on top. There was also Wasabi (the hot green stuff) and soy sauce, so everything that’s necessary - except chopsticks. But that wasn’t too bad, now that we are in the age of fingerfood.
What’s still bugging me is Guy Steele’s talk. So many new (and old) ideas for a new programming language (and he said that they had already taken out the really crazy ones), so I still have some research to do today. More tomorrow … WOW!

JAOO - Day 2

October 3rd, 2006

Day 2 on JAOO was the day of the great party (that’s why I am providing this post one day late) and great talks.
It all started by an inspiring keynote from Amazon’s Werner Vogels talking about Amazon’s platform - and how they got there. I read an interview with him in a recent ACM Queue or Communications, which was rather simular, but still a great talk.
Next on my list was the famous Bertrand Meyer talking about new concurrency concepts they implemented in their SCOOP system (which is based on the Eiffel runtime). Really interesting what kind of abstractions they used for those concepts.
After the lunch break I wanted to see Martin Fowler on Event Patterns, but unfortunately he had some problems with his back and could not come. His substitute was another ThoughtWorker, but he was not as good as I would have expected Martin Fowler to be.
A small intermezzo on the feedback that the attendees give after each talk: you just put a green, yellow or red paper card into a basket, and that’s it. So green means “Great talk!”, yellow means “T’was ok.” and red shows that there was something wrong with the talk.
So the Event Patterns talk was the first yellow for me.
Then there was Eric Evans’ two-hour talk about Domain Driven Design - really great talk (definitely green).
Next for me was a panel discussion on Abstractions for Concurrency with Bertrand Meyer, Denis Caromel, Satnam Singh and Joe Duffy. During the discussion I regreted not having seen the others’ talks: Singh for example had his about transactional memory - a really hot topic.
Day 2 ended with Alistair Cockburn (”with a silent ck” as he insisted once again) stating that “Methodologists are Blue-Green Algae and Methodologies are Swimsuits”. Brilliant talk again and fun to watch and listen to!
Did I say day 2 ended already? It did not, because this was just the time the great JAOO Party started. With all this free beer and good music I stayed longer than I should have.
On the other hand it couldn’t have been that bad, as I’m currently blogging in the hotel’s lobby and sipping another beer…

JAOO - Day 1

October 1st, 2006

Well, what should I tell you. It’s like a dream come true - I’m at the JAOO conference in Aarhus/Denmark.
After some extreme-airport-hopping (4 airports in 7 hours) yesterday and some major problems with the local geography (getting to my hotel), I still managed to survive JAOO Day 1.
On today’s program were some parallel sessions about Ruby on Rails, Spring, Equinox/OSGi and Test Driven Development. I participated in the Equinox and TDD sessions.
The former was held by Tom Watson and Jeff McAffer, two guys from IBM. They first explained the ideas and concepts behind OSGi, followed by a live presentation of a simple “Hello OSGi” bundle (those attendees who had their laptop with them were encouraged to try it themselves). They also provided the source code of a simple chat application, but due to all the (really interesting) discussions, there wasn’t enough time left to try this one in the session (but I started it and - well - it worked).
The bottom line: OSGi is a really interesting technology for glueing your components together, solving all of your classpath issues (well, not quite that is). A minor “problem” is, that development is a little different from “normal” Java development (as with every container there are new things to learn and understand).
Another problem is, that some libraries using a Thread’s context ClassLoader have problems running as OSGi bundle. Unfortunately one of these libraries is Hibernate, which would pose a problem for many people wanting to use OSGi on the server. Luckily there is the concept of a buddy classloader solving this problem, but this is not (yet?) part of the OSGi standard, but only provided by Equinox.
Session 2 - Test Driven Developmen - was moderated by the ThoughtWorker Erik Dörnenburg (I was waiting the whole session to hear the name Martin Fowler, but it just didn’t come). It was a good practical presentation about TDD and what it’s all about (to sum it up: red bar - green bar - refactor, in this order).
The second part of the session was an introduction into jMock. I found out, that I disliked it for a false reason. I always liked it because of its concise syntax (compared to easymock’s record-and-replay mechanism), but I thought that it was somewhat brittle to provide a method’s name as a string (e.g.

mock.expect(once()).method("someMethod")

). This of course poses a problem when you refactor your classes, but the key point is that your test will fail if you provide an invalid method name (jMock checks if a method with the provided name really exists). So you will find out if you did anything wrong.
Well, that’s about all from JAOO Day 1. What’s left is a pleasant feeling in my stomach - the reason may be the most expensive 3 small pieces of roast lamb I have ever had (26 Euro) or the most expensive beer (6,5 Euro for 0,4l … even at the Oktoberfest in Munich you get twice as much). Good night.

It ain’t easy to be simple

July 31st, 2006

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away (Antoine de Saint-Exupery)

Everything should be made as simple as possible, but not simpler (Albert Einstein)

What do these quotes, the Rube Goldberg machines, Occam’s Razor and the KISS principle have in common (Google and Wikipedia keep impressing me what you find by just searching for a simple little word)?
Well, they are all about SIMPLICITY (or lack thereof)!
Simplicity is also a central tenet in software engineering and development.
I’ve seen really great pieces of software that unfortunately were complex and awkward to use. I’ve seen classes that were simple to use, but that had so many different responsibilities that they were hard to understand and maintain. I’ve seen design rules that were supposed to make implementation for the programmers as easy as possible, but resulted in a big pile of overly redundant code (this is also not simplicity).
Simplicity is all about reducing this complexity as much as possible.
In software engineering, this principle should be applied wherever and whenever possible.
When designing and implementing, the class’s internals should be simple (not too much responsibility for a single class - this is where high cohesion comes into play), but also its interface should be simple (the Spring guys, for example, are doing a great job wrapping and simplifying complex third-party classes and components).
But this is also true for a system’s architecture. System components should be as simple as possible, resulting in probably more, but simpler components.
And last but not least, simplicity also makes sense for processes - the build process and the development process (I don’t want to use the agile buzzword here … oops, too late).
I think a good metric is, how easy it is to describe a component. If you can say in a few sentences, what a component does, then it is probably simple enough. This applies to classes, but also to system components or subsystems.
And a final note: the goal is avoiding complexity, not negating it.

The Cradle of Initialization

July 27th, 2006

First of all I’d like to announce, that (as a result to a suggestion for improvement) it’s not necessary any more to subscribe in order to post comments on this blog - so please feel free to put your oar in (you too, Mario)!
Ok, todays post started off as a question from my colleague Chris about what would happen in Java if an Exception was thrown in the constructor. And it ended with, well … read for yourself.
After we decided that Java’s behaviour in case of an Exception in the constructor was still quite decent, the next step was to have a look at class initialization - what happens if an Exception is thrown in the static initializer for example.
First Attempt: we try to throw a RuntimeException (something gives me the feeling, that only an unchecked Exception will work here):

	...
	static {
		throw new RuntimeException("oops");
	}
	...

Hey, not even a RuntimeException works. The compiler complains about the initializer not completing normally. Of course not, stupid compiler! That’s what we wanted!
But we wouldn’t be in the software business if we hadn’t fooled the compiler once or twice.
Second Attempt:

	...
	static {
		if (true)
			throw new RuntimeException("oops");
	}
	...

Gotcha, smart ass! When we try to run our class (added a main method for that), we get an java.lang.ExceptionInInitializerError. That’s what we wanted.
Third Attempt:
Not much unexpected behaviour yet. What can we do now. Hmmm … I remember someone saying, that it’s a bad idea in a constructor to expose this (the object currently being constructed) to another object (or even thread).
Ok, if that’s a bad idea, then exposing an object from inside the static initializer must be a very bad idea. So, let’s go.
A “good” way to expose an object is to register it in some registry. So we start with this registry:

public class Registry {
	private static SelfRegistered registered;

	public static void main(String [] args) {
		try {
			SelfRegistered.init();
		} catch (ExceptionInInitializerError err) {
			err.printStackTrace();
		}
		registered.hello();
		SelfRegistered registered2 = new SelfRegistered();
		registered2.hello();
	}

	public static void register(SelfRegistered selfRegistered) {
		registered = selfRegistered;
	}
}

And then the class, that creates an instance in the static initializer and registers it in the registry.

public class SelfRegistered {
	static {
		Registry.register(new SelfRegistered());
		// in some cases, something happens
		if (false) throw new RuntimeException("oops!");
	}

	public static void init() {
		// do some init stuff
	}

	public void hello() {
		System.out.println("Hello from " + this);
	}
}

So if we run the Registry class, the SelfRegistered.init() method is called, which does actually nothing, except that it of course causes the SelfRegistered class to be loaded and initialized. So before the init method does its nothing, the static initializer is executed, creating a new SelfRegistered() and registering it in the registry. The Exception is of course not thrown, because the condition can never evaluate to true.
Then, after the static initializer and the init method, we are back in the Registry.main method, where the hello method is first called on the registered object, and then on another instance of the SelfRegistered class.
We run it, and we get something like:

Hello from SelfRegistered@57f0dc
Hello from SelfRegistered@32c41a

Last Attempt:I have the feeling, that we are on the right way, so let’s quickly see what happens if the RuntimeException is thrown in the static initializer. So change the line in SelfRegistered to:

		if (true) throw new RuntimeException(”oops!”);

… and run it!
Wow … the output looks like this:

java.lang.ExceptionInInitializerError
	at Registry.main(Registry.java:8)
Caused by: java.lang.RuntimeException: oops!
	at SelfRegistered.(SelfRegistered.java:7)
	… 1 more
Hello from SelfRegistered@6a55fa
Exception in thread “main” java.lang.NoClassDefFoundError
	at Registry.main(Registry.java:13)

So if we carefully read this (with the other eye on our code), we see that during initialization of the SelfRegistered, after registering an instance of this class in the Registry, the RuntimeException was thrown, which caused class initialization to abort.
After catching this error, we try to call a method on the registered object, and - surprise surprise - it works!
But the class cannot be completely initialized, can it? The static initializer failed!
Well, of course it is not initialized, as we can see in the next lines, where we are trying to create a new instance of SelfRegistered - which fails.
The Moral:
What we learn here is, that it’s usually not a very good idea to expose an object from inside a constructor or even static initializer. This gets even more dangerous if Exceptions may occur (which is practically everywhere, as we know).
But the most important lesson is that even Java does not always behave the way we would like it to …

TODO or not TODO?

July 25th, 2006

Despite the already very ambitious subtitle of this blog Daily Dose of Software Engineering - and I mean the Daily part -, especially considering my posting habits in the past, I somehow managed to write my second post in just one day! Maybe a good omen…
This one is about a feature of an automatic build process.
We all know, that an automatic build process is a good thing (at least we should know by now). Along with the right tool and plugins, it makes sure that the code always compiles, the unit tests produce a green bar, the coding guidelines are respected by all developers and certain metrics are in a valid range.
Another feature that should be used much more often is, that pending implementation tasks (those nice TODO comments that a developer can put into his code if he is not really done yet) can easily be managed. Developers are usually very diligent adding such comments (mostly to defer dull or complicated tasks for later), and build tools have very good support for creating lists of those TODOs.
The problem is usually, that those comments are added to the code, the task lists are created, uploaded to the project’s developer web site, and … well, stay there without ever being checked (in the hot phase of a project, which is usually always, nobody wants to find some more skeletons in the project’s closet).
Here are some ideas that might help prevent this problem:

  • If you don’t do that already, add those TODO comments whenever you defer some implementation task for later, and use your build tool to create a publically available list of those implementation tasks
  • Before a release, the developers are responsible for checking their tasks, if they are relevant to this release (note, that you need to know, which tasks belong to which developer) and complete them if necessary (and then of course remove the TODO tags)

If these simple rules are obeyed, chances are small that your test team finds a bug, the developer looks for a possible fix, just finding a TODO comment saying exactly what should have been done in the first place to prevent this bug.
Finally, just a little story about a TODO comment we found some time ago - it was something like

  /*
   * TODO change this by version 5.3
   */

Well, believe it or not, we found it while adding some features for version 5.8 ;-) .
So back to our question TODO or not TODO? - the answer is definitely TODO!

Blogging Revisited

July 25th, 2006

So this is another attempt to get my blog going (should I say rolling?). If you’d have been on this site before, which you probably haven’t, you would have seen an installation of a simplePHPblog with exactly one blog post. In this post I promised to post more often than on the site I had before (which was actually a WIKI with 6 pages or so).
Well, so much for this promise - it didn’t quite work out the way I wanted it to.
Ok, as you can see, I just installed WordPress which I always wanted to have - unfortunately I didn’t have access to a database on my provider’s server. Well, now I do, and - et voila - WordPress to the rescue.
But enough of this now - I do not want to bore you with the long story about my first trial (and errors) concerning my site. Just as much, in future posts, I will try not to impose too much dull information upon you about my private life, my brand new car or my digestive system.
This blog is about software, and it is about software only.
There will be posts on Java, development tools, development process, object oriented stuff and software engineering in general.
So stay tuned for more…