Thursday, March 13, 2008

Today's riddle: why does CUP emit the generated parser as TWO classes?

OK, so when you use CUP to generate a parser, it emits two classes: a parser class, and an action class (which contains the code generated for the semantic actions associated with the productions of your grammar). These are totally separate classes.

Today's riddle is this:
Why is the code for the semantic actions generated in a separate class?
Here are some possible answers:
  1. Your guess is as good as mine.
  2. Look in the user manual to find out --- oh wait, the user manual doesn't explain this.
  3. To ensure that you must violate encapsulation in order to allow semantic actions to refer to internal parser operations?
My complaint is that if you want add additional fields--for example, a symbol table object---the semantic actions can't directly refer to it!

The action code can refer to the parser via a field called parser, but that's only useful for calling public methods on the parser object. But that means that any internal parser state/operations that the semantic actions want to access must be exposed as public, violating encapsulation.

Blech.

Wednesday, March 12, 2008

GUI Builders for Eclipse

The time has come to talk about GUIs in the Software Engineering course I'm teaching currently, which led me to revisit using a GUI builder in Eclipse. (I will not hand-code a Swing GUI. I just won't.)

Previously I've used the Eclipse Visual Editor plugin, which, while not perfect, generally gets the job done. To my dismay, the current release of the VE does not work with the current stable release of Eclipse, and there has not been an official release of the VE since June 2006. (So sadly neglected / and often ignored / a far second to Belgium / when going abroad / Finland, Finland, Finland :-) I hope this project gets reinvigorated at some point, but I wasn't going to sit on my hands waiting for that to happen.

A quick google search turned up Jigloo, an Eclipse-based GUI builder which, while not free software, is gratis for non-commercial use. From my 10 minutes or so of using it, it appears to be very nice, quite a bit more polished than VE. We'll see how it goes, but I'm cautiously optimistic it will do what I need it to do.

Tuesday, February 26, 2008

ArgoUML

In teaching a course on Software Engineering and Design this semester, I have rediscovered ArgoUML. Briefly, it's a UML design tool along the lines of Rational Rose or Visual Paradigm. I can briefly summarize its strengths:
  • It works pretty well, especially for basic uses (creating UML class diagrams)
  • It's free software (in the sense of both freedom and money)
  • It's a pure Java application, and works well on any platform supported by Java
Given those strengths, its a natural fit for an academic course, and in a more general sense is appealing to anyone trying to rid his or her life of proprietary, closed-source software.

ArgoUML's main drawback is the lack of an Undo feature, which is certainly a bit disconcerting. Web search hits of the ArgoUML development lists seem to indicate that this feature is in the works; if it gets done, then I my enthusiasm level would go from "pretty cool" to "KICK ASS". Even without Undo, it's still a good choice for occasional UML modeling needs.

Wednesday, February 13, 2008

Elias Swope Hovemeyer


Born Friday, February 8th at 7:32 PM, weighing 6 lbs 12.8 oz.

Tuesday, February 5, 2008

Java Software is a Good Thing

I'm teaching a course on Compiler Design, and I'm going to have students use JFlex and CUP as the scanner and parser generators.

I always dread asking students to use any software besides Visual Studio or Java/Eclipse, since it means I have to worry about whether or not
  • they have it installed
  • they have it installed correctly
  • they have the right version
  • etc.
I also have to make the build scripts configurable so students can customize them to reflect where they have the tools installed, which of course is another place where things can go wrong. Plus, I have to ask our IT department to install the software in our lab, etc., etc.

It occurred to me today that JFlex and CUP are both written in Java, so I could simply include them in the assignment skeleton! This took me all of about 5 minutes. Now I have a compiler assignment skeleton that requires only Java and Eclipse. In fact, it has an Ant script, so you don't even have to use Eclipse. So far I've only verified that it works on Linux, but I'm pretty confident that it will work on Windows, too.

JFlex and CUP are both free software, so there are no license issues to worry about.

Monday, February 4, 2008

The Vague Syntax of Ruby and Ruby on Rails

I like the Ruby programming language a lot, and the Ruby on Rails web application framework is one of the best ones out there. One characteristic they share is an emphasis on writing concise code. Ruby pares down the syntax of writing object-oriented programs to a bare minimum. Rails emphasizes the use of a small number of conventions and idioms in order to avoid specification of all but the most essential details.

However, I think that both Ruby and Ruby on Rails take the principle of brevity to an unreasonable extreme. Here are a few examples.

First, Ruby (the language) does not require parentheses around conditions or method arguments. So, you can write
foo.bar baz, thud
instead of
foo.bar( baz, thud )
In the second form, isn't it much more obvious that we're calling a method, and that baz and thud are the arguments?

As an even simpler (and more ambiguous) example, say that you see this code in a Ruby method:
blat
A bare identifier does not really provide any clue that would suggest to the reader how the identifier is being used. In this case, it will be interpreted as a method call with no arguments. Wouldn't it be much more clear like this?
blat()
I think the general lack of visual cues in Ruby code makes it difficult to read.

Rails code (at least in the books and on-line tutorials I have read) tends to opt for the same kind of extreme brevity. For example, consider the following code:
redirect_to :action => :login, \
:destination => request.request_uri \
and return false
I found this code in an implementation of user authentication using something called Confluence4r. The code specifies what should happen when a privileged action is attempted without the proper credentials being present in the user's session. It's reasonably clear that a request is being redirected. However, an options hash is being used to specify the details of the redirection.

I guess that options hashes are good in the sense that unnecessary information can be omitted. However, I think options hashes are overused in Rails. An options hash is basically a "magic bag of goodies" that a method will use to carry out some behavior. However, the specification of the options hash at the call site does very little to inform the reader how the contents of the hash will influence the behavior of the called method. In the case above, it's reasonably clear that :action => :login will redirect to the login action. However, what is going on the :destination key? As far as I can tell, it simply puts request.request_uri in the query parameters of the redirected request, but I fail to see how that behavior is even hinted at in the text of the method call. Wouldn't something like the following be much clearer?
next_request = Request.new()
next_request,set_action( :login )
next_request.add_param( :destination, request.request_uri() )
redirect_to( next_request )
return false
Sure, we replaced 1 line of code with 5, but the reader would have a much better chance of figuring out what is going on.

Sacrificing a bit of brevity in order to get self-documenting code seems like a good tradeoff to me.

Wednesday, January 9, 2008

Back to work!

I'm getting back to work after a very enjoyable holiday break. I was able to play a significant amount of Super Mario Galaxy while I was on vacation; it's a very good game, and (IMO) better than Super Mario Sunshine, but still not as good as Super Mario 64.

I'm teaching a Compilers course in the Spring, so I'm beginning to get things ready. Today I played around with JFlex and CUP, which are Java equivalents to the ubuquitous lex and yacc. As much as I enjoy the occasional bout of C hacking, Java is a much better teaching language. I put together a simple JFlex/CUP example that demonstrates integrating a JFlex lexer and a CUP parser. JFlex and CUP are designed to work together, so it wasn't a huge task.

Next task is to investigate using Jasmin to compile generated JVM bytecode.

My colleague Dave Babcock and I are working on a paper to submit to ITiCSE 2008. It will describe a nifty sequence of CS1 programming labs and assignments. Getting stuff published in CSEd conferences is always a crap shoot, so we'll see what happens.

WXPN radio started broadcasting in the York/Lancaster area in the Fall, and I've been enjoying it a great deal. One important musical discovery I made via XPN is Neko Case: her most recent album, Fox Confessor Brings The Flood, is one of the most brilliant things I've heard in a long time.

A major event is going take place in February...more later!