October 08, 2009

I won the JFXStudio challenge of september 2009!

Last Sunday, Joshua Marinacci announced the winner of September's JFXStudio JavaFX coding challenge. Now, guess who won. Yes, me!

The challenge was to write an interesting application in just 30 lines of code (or 3000 characters), in the theme "time". Most submissions were clocks of some sort, and so was mine. I don't know what made me came up with the idea for a pacman clock, but I did, and it made me win the challenge too!

I have tried to stuff as much interesting behavior in my clock as I could while staying within those 30 lines of code.

Here are some of the tricks to pull that off:

  • Against all sound coding principles, I used lots of cryptic, one letter variables and functions with really short names (like "lz" for "leading zeros", and now I am reading back my code, I could have made it even more compact if I had defined a function "r" for invoking Math.random),
  • so, it is a good thing I also used this important object orientation principle to keep things compact and be able to create autonomously haunting ghosts: encapsulation
  • I used a constant named "forever" in stead of Timeline.INDEFINITE for all the TimeLine instances used in the application,
  • I used SVGPaths, which are a bit cryptic, but very compact,
  • I avoided typing spaces and carriage returns as much as I could,
  • and I tried not to care too much about code readability (which, for a Java developer like me, is a very hard thing to do).
So, as you can see, I squeezed JavaFX as much as I could, and out comes a fun to watch little clock. My kids love to watch it!

You can webstart the pacman clock here, and you can download the source code to see if you can make any sense of it (I know I won't be able to after a year or so) here.

This challenge was a lot of fun! Hopefully, I will find some spare time to enter next month's challenge. This time, we are challenged to write a 30 line (or 3000 char) app again but now in a different theme: "five". Let's see, what can I make of that...

five
alive
hive
jive
live
strive
drive
...


No comments: