Monday 3 October 2011

First (Programming) Language

Using C++ as a teaching language is a very dumb idea.

Programming is about all the programming concepts. Languages implement those concepts. Which language you use doesn't matter, as you are using the same way of thinking[1], expressing the same concepts.

While this is true for programming, learning programming is whole another thing. When you don't have the concepts, simultaneously learning the specific language syntax will distract you. That's why things like loop and conditional are usually taught without mentioning syntax at first. Learning semantics and syntax at the same time is hard. With C++'s complex and cryptic syntax, the distraction is so big to the point where some students never understand the programming concepts.

Take the for loop for example. In C++, the syntax of a for loop is:
for (initialization; condition; action-to-counter;)
An example is :
for (int = 0; i < 10; i++)
You can omit any one of those. In fact, you can omit all of them. Therefore, the following is a valid statement in C++:
for (;;)
This is a way to achieve an infinite loop in C++. The problem is, this obscure the line between for loop and while loop. Yes, this is a valid command, but it does not convey the concept well. Compare to the usual pseudo-code:
for i in 1 to 10
one can really see the syntax from Python:
for i in range (10)
and the one from Ada:
for i in 1 .. 10
is clearly superior, and the C++ one is really cryptic. C++ is too close to the metal; the high-level programming concepts is behind too many abstractions, or rather, details of the underlying hardware. Some may argue that it is this thing that distinguish brilliant programmers from the mediocre, but I say that this undermines so much brilliance.

Actually, this syntax of for loop comes from C, and I condemn every language that copies it. This includes but is not limit to C++, C#, Java, JavaScript, and PHP. For a programmer, learning a new syntax of a different language is a matter of minutes, if not seconds. But, for a newcomer, learning the concept of for loop from this syntax can be a painful process.

Using C++ to teach programming is a very dumb idea, especially when teaching someone who has never learnt programming before.

Pedantic footnote:

[1] With some variation. due to the characteristics and limitations of different languages, you may or may not convey some ideas or concepts in a language.