<< Dear Microsoft, ... | Home | Oh lawks... >>

Newsflash: Java unsuitable for beginners!

I've been teaching an introductory course here at the African University of Science and Technology in Abuja, Nigeria, for two weeks now.

My 16 students hold BSc in CompSci and Math from universities all over Africa, but there's only one in the class that already knows Java. There's some unfortunate exposition to VisualBasic, the occasional Pascaler and even Python and Fortran (Heavens!).

I spent the first week teaching the plain programming stuff: declaring variables of primitive types, the usual control structures (if-then-else and for/while-loops), and method definitions and recursion.

That seemed to work rather well, instructing them to create an fresh Java class in Eclipse for each assignment and simply take the magic public static void main() for granted. However, the correct placement of semicolons and brackets did not come easy to them.

A few of them still struggle with the concept of a variable, for example when simply summing the values from 1 to 100 in a for-loop. But that can be forgiven, as I also have a hard time motivating it in a non-memory-centric way. Also, in the presence of multiple methods, it was no longer clear (a) where execution starts, and (b) what happens if you encounter a method call. Similarly, there was a lot of confusion about printing values and returning values. But all in all, it seems they took on recursive solutions more easily than iterative ones (despite the confusion about method calls).

Enter Object-Orientation. Of course there's some startup penalty for motivating and introducing the concept of OO, which seems to stick. However, all the technical/mechanical problems from before (syntax, order of execution) now get into their way. Unfortunately, the math lecturer decided to bring in his teaching assistant which eats up the students' precious time for revisions in the evening with another math tutorial from 20:00-22:00! Which means by now at the end of the second week where we should worry about more conceptual things (inheritance, interfaces, exceptions), most of them still don't manage to write a syntactically correct Java program containing more than the initial class.

The difference between variables and attributes is also still mystifying them: if I write in the main method

Box b = new Box();
b.width = 25;
why can't I use b.width in a method for class Box? Likewise, many prefer to pass the object (subject) as an argument, so occasionally I find code like
class Box {
  int w,d,h;
  int volume(Box b) { // or just int volume(), because that's what the slide said...
    return ( b.w * b.h * b.d );
  }

  public static void main(String args[]) {
    Box b = new Box(25);
    System.out.println(volume(b));
  }
}
which of course doesn't even compile for obvious reasons.

Two more problems are communication and overall problem managing skills. Most of them speak very good English, but lack precision when taking about things: e.g. a boolean variable called open, representing whether a door is open or closed, a method called open(), the notion of a closed door (the value of attribute open is false).

Occasionally I will give fragments of (working) source code on the whiteboard or slides with ... eliding (what I though) well-known details (public static void main(...)) that they either ignore or copy incorrectly, thus spending precious amounts of time on syntax instead of solving the problem.

One more week to go, but I will leave with the definite confirmation that either I'm a bad teacher, or you should really start with Haskell or SmallTalk as an introductory language (which we already new anyway, right?). Java's (syntactical) concepts are by no means clear (to a beginner), it requires a lot of special casing (why is at least one class public, what is the static qualifier), and the important notation of and order of evaluating sub-expressions is not as prominent as it should be (although this could be explained in Java as well as in Haskell).


Did you know that foldr.org pursues the proliferation of functional programming in industry and teaching?
Tags : ,



Add a comment Send a TrackBack