State machines and scala.swing

June 4, 2009 at 10:49 pm (Scala, Scheme, Week 11) (, , , , )

After some morning refactoring on my Scala Tic-Tac-Toe (including moving my computer player’s minimax algorithm to a completely functional style) and speed tweaks, I moved on to thinking about how to integrate a GUI. Micah’s told me it’s not a requirement, but I’d like to have another crack at GUI development – I was very slow thinking things through in Java. Micah and I had talked yesterday about the possibility of a state machine to hold the game state so that my other application logic didn’t need to concern itself with whose turn it was. I have mixed feelings about it: on the one hand, state is what I’m trying to avoid in my functional programming study, but on the other, it’s apparently a very widely applicable design pattern that I ought to learn anyway.

At any rate, I spent the morning and most of the afternoon looking into SMC, the state machine compiler. Apparently there are numerous different ones (all named SMC) floating around on the internet. I believe all of them started with Uncle Bob‘s idea, and the one I’m using does give him credit on the website. It’s really like stepping into a second new language (DSL) writing state tables for the state machine compiler. I’m sure that the benefits will outweigh the time I needed to spend reading the documentation.

At the end of the workday, I fooled around with Scala’s Swing library (a wrapper for Java Swing). There are still some Javadocs I needed to dig into to understand what I was doing, but I was able to pick up the syntax pretty quickly. I have to say, Scala really does seem to be Java++. The Java libraries are still super-easy to grab, and the syntax is similar enough that it feels closer than it did with JRuby. The advantages I do see to Java are a familiar syntax and proliferation of tools, especially IDE support for refactoring – Scala’s IntelliJ plugin is good and has a few refactorings, but it has plenty of room for growth.

I spent some time tonight going back over my slides for tomorrow’s Lunch & Learn (“Scheme for Rubyists”), going through the presentation once for my wife and our dogs. I found a couple of outright mistakes and several extra points I needed to make, so it was good practice. I also went through a kata in Scheme that I’ll do tomorrow for the group if we have time. Wish me luck!

Permalink Leave a Comment