Wednesday, June 18, 2008

Why I Taught Programming with Java

I teach a high school computer class, and this last year we spent a semester learning programming. Picking the computer language we'd use was a lot tougher than I expected it to be. I looked at a lot of languages, and a lot of implementations of those languages. I ended up using Java.

I wanted a language that the students could use on their own, outside of class, to do real things. The language also had to be supported on multiple platforms, with the same syntax and libraries/classes on at least the major desktop OSes. It also had to be free, in the sense that there'd be no license fees for the school

On top of that, I wanted it to be fun, something that would let the students play with graphics and sound. Console-mode text just didn't cut it.

Now, in this day and age you wouldn't think it's expecting too much to have a programming language support features like graphics and sound, right? Apparently the language developers think it is. They rely on hooks to proprietary APIs, mostly, meaning that the code to open a window on platform A is completely different than that on platform B.

I'm not talking implementing keywords for controlling specular reflections and bitplane operations, here. I'm just looking for windows and some basic drawing primitives in the way of graphics. For sound, the ability to play a tone or a simple audio file would be plenty.

I was hoping to use a language with a clean, simple syntax like ruby or python. But I didn't find an implementation of either that met my needs. Jython came close, but the hurdle of jumping the Java API barrier to get the graphics and sound undid all the good that the core python would do--it would be easier to just teach Java from the outset.

I also considered going with Berkeley Logo. I like Logo a lot, basically it's LISP with some of the historically-established keywords cleaned up. I may use it this upcoming year with my middle school class. But for my high schoolers, I wanted something with more of a real world presence. Something they could keep moving forward with without having to change horses. Honestly, an open LISP implementation with platform-independent graphics and sound capabilities would fit the bill. One look at Y Combinator is all it takes to see that LISP is alive in the real world. I looked at some LISP implementations, I'll be looking at some more, but in the time I had I didn't find something that did what I was looking for.

Less Than Perfect
There were still some snags with Java, though. Installing the SDK on the school's Windows systems was a pain. The extra step of changing the command path was annoying for me, and for my students who went to install it on their home systems it became an insurmountable obstacle in about half the cases. OK, to tech-heads this probably seems like foolishness. Some may say that if they're stopped by this they have no business programming. I don't see it that way, and I don't take kindly to folks who think unnecessary complications in installing and using software ought to be used as a worthiness test for beginners. Beginners are beginners, and they ought to be able to focus on the one thing they're working on learning at any one time.

And, face it, as Windows users they're not used to install procedures any more complex than spinning a disk and clicking on a button. It's a shame users of all platforms couldn't have it that good.

As the aficionados of the scripting languages point out, Java's syntax isn't a simple and straightforward as it could be. To new programmers its insistence on certain forms of capitalization make it seem pretty fussy, for example, and dots meaning one thing in an import statement and another with invoking methods and members is more class time lost.

I used a Java textbook for non-programmers in an attempt to make my life a bit easier. I wasn't entirely satisfied with the any of the available Java programming books I was able to review before we got started with Java in class. As basic Computer Science books, I think they were fine. As introductions to casual programming, there were none that fit the bill. I'll try to do mini-reviews of the books I looked at and used in some future post. But my main concern was that the fun stuff--graphics and sound--was all left till late in the books. I had expected to find something that presents some basics like a JFrame and paintComponent early on, then plays with flow control constructs and such by using graphics within them. Unfortunately, I didn't find any such Java books for non-programmers (or for programmers but basic enough that I could make up the difference.)

Looking Forward

I'm planning on spending a semester on programming again in this upcoming school year. I haven't decided if I'm going to stick with Java, though the default will be doing so. If I do stick with Java, I may create a LiveCD of some sort with the SDK and a basic IDE on it, and distribute it to the class. This could get rid of some problems I had last year, like dealing with some of Window's programmer-hostile features in class while neglecting the students on other OSes, as well as installation of the SDK on the computers in the school's lab (the non-Mac OS ones, that is.) It'll also mean that the student can take the CD home and have the same development environment there as in class.

I'm also still looking at other options. Because I still think it's worthwhile to have some graphics and sound in an introductory class, and because I still want the students to be producing portable programs, I'm concentrating on the language implementations that compile to Java bytecode. If I find a language that doesn't have some of Java's gotchas for beginners, it won't be any worst to install its compiler (except that I'll have to add it to the OS X systems as well as the others, unlike the Java SDK.)

Groovy is one possibility I've found so far. JavaFX may be another. Whatever language I choose, I may still go with using a LiveCD of a BSD, Linux, or maybe even OpenSolaris depending on what I can find that works well with the lab's computers and is likely to work well with most students' home systems.

I can tell you this, though. As "bad" as it was, it's times like this that I really, really miss those old 8-bit computers with BASIC on them.
There was an error in this gadget