2005-07-16

On kids and programming

For the past two days I'm fighting on a Croatian #linux irc channel with a guy nick-named Neuromanx. He is a teacher at high school in a small town of Ivanić Grad. He is also working in a local computer club with smart elementary-school pupils, preparing them for competitions in programming. He boasts himself to have made many of his pupils champions on national competitions in programming. All of his pupils achieved their excellent results programming in Basic. So what am I fighting with him about? He wants to teach them C and/or C++ before they enroll in the high school. And I'm talking about kids 13-14 years old!

I think that it is a bad idea, both for teaching them a more "powerful" language and for making them more successful in competitions. These are my reasons:
  • One needs to know fundamentals of computer achitecture to be successful in C or C++ - you know, stuff like memory addressing, two's complement and such. Unless you're comfortable with low-level concepts like bits, bytes and machine addresses - don't even try to understand how pointers, multiple pointers, function pointers or integer arithmetic rules work (e.g. you can easily get a negative number by adding a positive number to another positive number!).
  • Knowing assembler helps. I have grasped how pointers work in C only after I did some programming in assembler. After writing a few programs in assembler and trying to interface ASM functions with C.. came that 'a-ha!' effect after which I really grasped pointers.
  • C compiler messages are often baffling and unintuitive (just try forgetting somewhere the terminating semicolon.. often you get anything but the simple error message in the lines of "semicolon omitted at line..."). C++ is even worse in that respect, especially if you mess up something with the STL.
  • C and C++ allow you to do much, but rarely warn (unless you explicitly tell them to) that what you're doing is probably wrong. They are very forgiving. In other words it is extremly easy to shoot yourself in the foot and can be extremely hard for a novice to figure out why the program is failing. It is possible to make almost any syntactically correct C code (a bit harder with C++) to compile and execute.. but chances are that it won't do what the programmer intended. Examples of such traps are signed-unsigned comparisons, implicit type promotion rules and operator precedence. Even I, considering myself an expert in C after having a decade of experience with it, make stupid mistakes like writing !x&1 instead of !(x&1) to test whether an integer is even.
Yes, C and C++ are powerful. Coming from the UNIX world, they have the same philosophy as UNIX - the user (programmer) is always right. That's why they provide dangerous constructs like type casts. For that same reason (among others) there is no undelete on UNIX (and rm asks "Are you sure?" only if you explicitly tell it to!) - because the user knows what (s)he is doing! This is excellent if you are an expert and really do know what you are doing. It just gets out of the way and enables you to do what you want without fussing around. But is very unforgiving if you don't know exactly what (and how!) you are trying to achieve something.

I am myself a strong proponent of Pascal for teaching someone to program. It was my next language after C64 BASIC and I have never regretted it. I have first started to use Oxford Pascal on C64. After it I have moved to Borland Pascal 7 on a 486 under DOS. The IDE was the best I have ever worked in (to this day I have to say!), included an intuitive debugger, the compiler was blazingly fast with friendly error messages. And it was extremly easy to use - just run the IDE, type your program and compile it! Modern C IDEs come nowhere near the BP in any aspects I have just mentiones.

Let's return to Pascal. Why would I recommend it to anyone wanting to learn to program? Because it teaches you discipline. I believe that you have to discipline yourself if you want to become master of anything, including programming. Pascal forces the discipline on you. Unlike C:
  • it was designed for teaching programming,
  • it is a very strict language in which you can't accidentaly make a semantic error like in C, therefore
  • it doesn't stand sloppines (e.g. no implicit conversions),
  • encourages you to learn structured programming,
  • doesn't bog you down with details of pointers and memory management (which in C you encouter in the very beginning - just reading something from the keyboard with scanf needs a pointer),
  • has more verbose, but more clear syntax than C to the newcomer,
  • and has one feature that I sometimes really miss in C: built-in set data type.
In my young days, I have also participated in national programming competitions. And yes, I've used Pascal every time. No, I've never been even among the first top three contestants. But I don't blaim it on the Pascal. I simply did not have enough theoretical knowledge and imagination. If I have an idea of how to solve the problem, I can do it in any of the many languages I know now (C, C++, perl, python, Pascal, a bit of Scheme, LISP and Java, Prolog, etc.)

Neuromanx says that he (and everyone around him) is 'allergic' to Pascal and says that C is more 'powerful'. He never did give a rational argument why Pascal is 'bad'. After me saying that you can do anything in Pascal (esp. Borland Pascal, Delphi and tehir extensions) as well as in C, his response was in the lines of: "You can also do with a sheep anything you can do with a woman." If he was alluding to sex he forgot that you can't have a child with a sheep :)

After this sentence (coming from a school teacher!), and his short-sightedness, I wonder myself whether he really cares what happens with these kids later, or he just wants to make a larger number in his personal record of 'produced' state-champions in programming.

And my statement holds firmly for the types of programs you are writing on competitions: a bit of file/input output (simple formats, no problem for parsing) and algorithmic tasks.

Let me also say that I have been teaching algorithms and data structures course on (a Croatian equivalent of) college. On that college the students first use Visual Basic and then they immediately move on to Visual Studio. And most of them are having much trouble. The C is too overwhelming to them with its details, and they are as much struggling with a complicated IDE as with C. And these are older people (at least 20) who did learn abot 2s complement and such stuff before coming to C.

Neuromanx is claiming that these kids are smart, but... I doubt it that they are that smart that they can successfuly grasp C and apply C with their level of background information.

I would compare his plan to.. putting someone to fly a plane, after he had experience only with driving a bycicle.

So in what am I currently programming? C and C++ of course! Why not Pascal? Well, unlike Neuromanx, I have my arguments and this article summarizes most of them nicely. Let me cite two sentences from that paper:
"I feel that it is a mistake to use Pascal for anything much beyond its original target. In its pure form, Pascal is a toy language, suitable for teaching but not for real programming."

I fully agree. And when I was learning to program in Pascal, I have never really noticed its shortcomings. I have to add that some of Kernighan's points do not hold any more with Borland's extensions to Pascal.

And of course, as I have written earlier, I consider myself an expert in programming, I know what I'm doing and now I want the language to be out of the way. In my learning days, I needed all the help I could get, and the Pascal compiler was really helpful.

The jump from Pascal to C.. was pretty easy once I have grasped the concepts of procedures, functions, loops, etc.. you know, the basic elements of structured programming. And the programming discipline I had acquired with Pascal saved me a lot of grief with typical beginner errors in C (which the students at the aforementioned college are also often making).

To conclude: I am really glad I have learned Pascal before C. And it had made me a better programmer overall.

3 comments:

Anonymous said...

Well, basically, I agree with this essay, that treatment won't make those children good programmers. But, I disagree with the principal mistake made - I think the first wrong thing was teaching those kids BASIC, not C. Yes, I agree, C can be very clymsy and especially for someone who is just learning how to program. But, if he manages C at last, he will learn. Or at least I think so. Don't mistake me, I made the same error - the first language I learned was BASIC. And I am most definitely NOT proud of that. Just my 2 cents.

Anonymous said...

I fully agree with this essay. I can say that Pascal was a good choice for my first programming language because I've learned how to programme easily, and it's a good base for learning more advanced and efficient languages :)

ecnelis said...

i accidentally found this article and i like it. i realize it is more than four years old but i'm hoping you'll see this comment and add your opinion.

as you are much more experienced in programming in various languages then i am, which language would you recommend for high school programming nowadays? i'm under impression that python is very nice for beginers because it has very strict syntax (not like pascal though), and it is powerful enough to use it also as a language for more serious projects. and, of course, it has large community, many libraries and other stuff.