3 ms·
I have no doubt that you can get 11-14 year olds to understand Java's Hello World in a single hour, but understanding a pre-written snippet of code is a wholly
by callahad 16y ago
I have no doubt that you can get 11-14 year olds to understand Java's Hello World in a single hour, but understanding a pre-written snippet of code is a wholly different beast from being able to make appropriate predictions and inferences based on knowledge gleaned from that code.
Could your students explain how main() was called? Could they create their own functions and invoke them based on what they had learned? And how forgiving would Java be of minor errors, say, creating class a class named HelloWorld inside a file named Hello.java? Why does the filename even matter, if the class's name is defined right inside the file, or vice versa? And if the class is in a block inside the file, why can't they just create another block like the first one and have two classes in the same file? Why do they type 'javac HelloWorld.java', but not 'java HelloWorld.class'? How can java find the HelloWorld class if you're not pointing it to the class file? Why is 'javac' so damn picky about the file name matching the class name when you don't point 'java' to any files at all?
Seriously, there's a ton of voodoo in there. Things break in surprising ways, and it's hard to synthesize new knowledge based on prior experience.
Take Python, on the other hand. You can address things in a much more controlled order, with each step yielding practical information, starting with
print("Hello, world")
which tells the students how to call a function, and pass it an argument. Every other time they call a function or pass it an argument will look like this. Then you can show them how to make their own function:
def hello():
print("Hello, world")
But nothing gets printed? Hey! You've just explained defining a function, and based on the previous example, they can probably suggest how to invoke hello(). At this point, they can easily make and call new functions of their own. Then you can go on to introduce the basics of OOP:
class Greeter():
def __init__(self, name):
self.name = name
def say_hello(self):
print("Hello, " + self.name)
Sure, the "self" is a little magical there, but hey, you're comparing this to Java. Plus, you've got an interactive console that you can jump into and poke at the darn thing. Hey, what do I get when I say g = Greeter("Saundby")? Oh a "Greeter object". That makes sense. What can I do with it? Well, we made a say_hello, so what's g.say_hello? Oh, a "method Greeter.say_hello of <Greeter object>." And hey, it's the same Greeter object as g!
What if the students want to make a new class? They just put it in the same file, like you would expect. What if they want to rename the class? They just do it.
And you run it with "python filename.py" which appears to work exactly like how every other command that operates on files. There's no explicit compilation step to forget or trip over.
Yes, you can teach kids to read and understand a Java program, but what do you gain by handicapping yourself and foregoing the pedagogical tools, like an interactive console, available elsewhere? Similarly, what do they gain by being deprived of such a wonderful and frictionless means of exploring and experimenting with the language?
- aphyr 16y agoSeriously, there's a ton of voodoo in there. Things break in surprising ways, and it's hard to synthesize new knowledge based on prior experience. I've written a nontrivial amount of Java including a sizable Android app (aside: thanks Dobrow!) and still can't complete basic tasks like mutexing, sockets, or file IO without looking them up on StackOverflow. Eclipse is the only thing that makes that language's rigidity even barely tractable for me.
- kenjackson 16y agoSeriously, there's a ton of voodoo in there. And your solution is Python? Not surprisingly, as a kid my 1st language was BASIC. My second language was 6502 assembly in 6th grade. I can honestly say that things didn't really click until I learned assembly -- things like line numbers bugged me, and some of the syntax in BASIC confused me (why does a function call have the same syntax as an array?). And then I studied digital logic circuits, with a brief diversion into CRT displays and video support in computers (I was really concerned about how did the information go from the computer to the screen) in junior high, and then C in 9th grade. Python has a lot more vodoo than BASIC did. And whitespace having meaning is truly confusing, especially as a kid when its unclear that there's really a distinction between different types of whitespace (this used to kill me with Makefiles when I first started with those). I guess my point is is that what a seasoned pro thinks of as voodoo is often very different than what a child just learning to program thinks is voodoo... especially young kids who like to ask lots of questions.
- callahad 16y agoI illustrated the post with Python since it's my language of choice, but honestly, many of Python's benefits as a teaching language apply equally well to other modern languages. If we can agree that experimentation is one of the most powerful ways to develop an understanding of a system, then by going with Java, you're consciously eschewing languages which support that goal by being: 1. Interpreted. It's hard to overstate the value of an interactive interpreter, which is in many respects akin to having a second instructor available for the students, on-demand. It can instantly answer questions about its environment, it makes exploration and experimentation trivial, and it's great when lecturing, as you can immediately explore any "what-if's" that your students raise. 2. More expressive. Aphyr demonstrated this pretty eloquently in another comment, but the less code that it takes to accomplish a task, the less code you have to understand before you're able to build something useful, and the easier it is to experiment as you go. 3. Multi-paradigm. If you're teaching someone programming, you want to be able to expose them to procedures, functions, objects, methods, recursion, etc. If you can do all of that in one language, you lower the mental barrier that your students must overcome before grasping each successive topic. I believe that those facilities are great assets for both exposition by the teacher and exploration by the students, and I do not immediately see a compelling argument in Java's favor which sufficiently justifies foregoing the above pedagogic benefits. If the goal is to teach and create understanding, then surely the instructor should employ the tools that most readily support that objective.