My Apprenticeship - Friday, July 2, 2004

02 Jul 2004

In the summer of 2009 I revisited my 2004 summer apprenticeship at Object Mentor. What follows is the original 2004 post and then some 2009 commentary.

We did use my code in the wiki conversion program. And while it was good to finish up that project, this meant we had to start working on the State Map Compiler. A program first written in 1993 in C++, then later re-written in Java in ‘98. No tests, very long methods, and the documentation gives lots of examples in C++ (which I don’t know much about – it seems like Java, but it most definitely is not.) The point of the program is to take in a simple statement of a ‘state machine’ and output source code that implements the state machine in either Java or C++. We are going to be adding a C# output option to this program.

Now, at this point, you might be wondering: ‘What is a state machine?’ Well, let me attempt to regurgitate the turnstile example. A turnstile has two states: Locked and Unlocked. If you try to pass through a turnstile when it’s locked, you’ll get quite a different response than when it is unlocked. A coin will cause a locked turnstile to become unlocked, but won’t do much to an unlocked turnstile. A lot of software engineering problems can be thought of a nothing more than a dressed up turnstile with a few more states. So it’s handy to have a program that takes in some information about a finite state machine and then outputs the basic code that you can build your implementation around.

Also, it’s pretty interesting to be working on a compiler. Software that writes other software (that, ultimately, will be translated into byte code, and then the byte code will be translated by the virtual machine so that the real machine will know what to do – quite a process).

Not a bad explanation of a state machine for guy who just learned about them that day: Good job distant-past-jake. I think ended up using a state machine pattern in my code submission to ThoughtWorks later that year.

I later worked on a huge java project that would generate something like 15 classes for every one written class. I soon got very tired of generated code (“Hey, why did my changes go away? Oh, it’s a generated class… (next line said forlornly) Guess I better go dig through the xml pit for what to change.”)