Teach programming with JavaScript

I recently posted on how I find current computer science education lacks motivation. Today I had the pleasure to listen to a keynote by Prof. Dr. Dennis Komm on how he approaches computer science education. He should know since he is a Professor of Algorithms and Didactics at ETH Zurich and hence at the spearhead of education for computer science in Switzerland. And in his talk he made a lot of valid points – but I still feel the issues raised in my last post remain unanswered by his talk. I will use it as an anchor to refine my demands.

a person sitting in front of a computer learning to write javascript by building a nice and blinking website
DALLE-2 generated interpretation of how it fealt for me to learn JavaScript.

A very important point raised by Prof. Komm is: for a novice programmer the computer is a black box. It is really hard to figure out what it can do and can not do. Especially with consumer friendly tools and apps (Google, ChatGPT) performing better every day, one may be tricked into thinking the computer can do anything, can think along or infer automatically “what the user wants”. This is very far from true, especially when looking at the fundamentals of computers. Then again, thinking about what the computer can actually do is hard when confronted with programming languages or arithmetic basic commands.

I once challenged a friend to come up with an algorithm to compute a convex hull and she ultimately failed. She failed because she did not know that computers can do stacks – and its totally not her fault because its just really not that obvious that this kind of stuff works. After some time learning about computers I figured out that they can be assumed as “available” but its definitely not clear that this works when looking at the basic operations a computer can perform.

After all, the computer can only do very simple arithmetic. To build a computer you actually just need to be able to increment numbers and some tape. But when starting to interact with a computer, you are faced with a plethora of features. It is hard to reduce this to a level that helps understanding how a computer works. Similar to how you can observe and understand the state of a scissor (move the handles apart, scissor blades open, insert paper, move handles together, scissor blades close), Prof. Kemm recommended an approach to computer programming that makes it easy to observe the state of the computer.

For this, he chose the turtle programming language. It only offers a few basic commands (moving the turtle in a specific direction, repeating instructions a certain number of times, defining variables, changing color, …) and has a very observable state – the current position of the turtle on the screen resp. its trace from moving. And I think this abstraction certainly helps understanding how computer programming works. That is – if you are really interested in learning this in the first place.

Because frankly, the turtle will not motivate you in any way to learn computer programming. The turtle is really 100% useless. No offense, the images that can be generated are pretty. But even very motivated students will not be able to achieve anything remotely interesting with it (as in, something more complex than a drawing). It is really just a toy example. And ultimately, this will demotivate students (IMO).

Instead, I find my own introduction to computers fit very well into the motivating category. I first got introduced into writing websites in pure HTML. This is not very different to writing a word document, you even have less confusing buttons and hidden menus to use. Just a few keywords and the brackets (“<“, “>”) to remember. This also gives you a very observable state (the rendered outcome of the website) but no real programming yet.

In a second step, we learned the JavaScript basics. Yes, JavaScript is a terrible language – that’s why you should really just teach a simple subset of the language at first. It comes with everything you need, variables, loops, etc. You can observe the internal state very nicely using i.e. the Visual Studio Code debugger, which lists all the variables you defined and can show you how the computer steps through your code. And next to that you have the ultimate observable state – the website that you can watch transform according to your commands.

What’s more is that if you are keen on diving deeper (as a motivated student), there is so much depth to the programming language. You can learn a lot more details. You can build highly complicated tools. And you can easily distribute the result! I.e. It is actually useful if you want to i.e. build a nice blinking website for your parents or to show off on the internet (such as nielstron.de).

JavaScript does not inhibit motivation at all, it gives you basic tools that hint at all the possibilities of what may come. And it does not bother you to care about the insanity of types that i.e. Java brings with it, or the painstaking accuracy that i.e. C or C++ demands of you. You can just start writing, no need to compile, run and see where and why something fails. This is the beauty of JavaScript. And maybe it would have motivated more of my former class mates to study computer science. At least more than making a turtle run in circles.

PS: In our case it was a robot that moved blocks but ultimately it was just as useless as the turtle.
PPS: BTW I am not saying it was not fun for me to program them. But I don’t see how they would have motivated my class mates to learn more about programming, because for it did neither.

Leave a Reply

Your email address will not be published. Required fields are marked *