CoffeeScript Syntax for Kids
CoffeeScript, with its highly intuitive syntax, has been a hit in the classroom. It is a language that largely gets out of your way. It works the way you expect it to. However, there are still some pitfalls. Here are some findings from looking at CoffeeScript programs written over a couple months in a school, and with my kids:
- Iced Coffeescript is helpful. In modern single-threaded code, all communication - including user input - is inherently asynchronous, involving callbacks. But it is a heavy lift to learn callbacks: for example, simple loops become complex recursions. The "await/defer" in Iced fixes this by allowing you to "block" a program without buying the full complexity of preemptive threads.
- But the syntax of await/defer makes it hard to learn. Ideally, one could use "await" before understanding the concept of "defer". Whereas waiting for an event is easy to understand, the concept of passing a continuation function is difficult. Defer should be implicit when there is no variable being received.
- The "for" loop is too hard as the first loop, because it requires the concept of a loop variable to have any sort of loop. It should be possible for kids to make a loop without knowing what a variable is. LOGO's "repeat" would be perfect.
- Allowing the "=" as an expression leads to confusion. It is really common for beginners to write "if a = b" and not notice the problem. This is a language design flaw that is shared by C/C++, perl, and Javascript. Python fixes it by making single-equals assignments illegal as expresions, and nobody complains about it. Coffeescript already has several ways of spelling the same concept; my recommendation would be to have a separate ":=" operator to use as assignment-within-expressions.
I've started to hack on a light CoffeeScript fork to address these issues, but I'm not sure it's a good idea. There are advantages to teaching "vanilla Iced CoffeeScript" instead of a custom language.
Posted by David at October 1, 2013 05:27 AM