Archive for December, 2013


Should we use JavaScript as a teaching language?

A few days ago Ashe Dryden mentioned she was looking into JavaScript as a possible language for teaching. Some argue that it’s a terrible language to start people off with. This got me thinking about the language a bit and whether or not it’s truly terrible.

I started learning programming with Java which is a pretty obtuse language. Even the most basic “Hello World” is about 15 lines long. There’s the whole public static void main(String[] args) which when you are beginning programming makes no sense. This is where scripting languages really win, you write stuff and you get results right away.

One thing I think we need to realize though is that building basic command line applications isn’t the most interesting. “Oh cool I made a computer say ‘Hello Chris'” but there are better things we can do to teach. For one, seeing something visual instead of a bunch of characters in a prompt is a good start.

This is where a language like JavaScript starts to make sense. When bundled with a browser, it comes with a complete widgeting library that learners can use to build some interactive applications. Using plain HTML and CSS they could build a text adventure game, though by adding JavaScript to the mix it can become far more interesting.

Creating games is a good way for people to learn. For one, it’s interactive which makes people more inclined to play with it which may even uncover bugs, pushing them to fix it and make their games better. If you were to give a group of students a basic introduction to JavaScript, variables and functions you could probably have students rolling out a Knots and Crosses game by the end of the day.

There are a number of positives that come with using JavaScript as a teaching language, the big one being that the student doesn’t really need to install any runtime. As long as they have a modern browser they should be good to go. Chrome, Safari and Firefox all come with excellent DOM inspection and debugging tools as well as a JavaScript REPL. I’ve been to a few classes where I was a Coach/Teaching Assistant, and getting an environment set up can be a massive time sink and it can be really discouraging for people just looking to learn. The language also comes with a lot of functionality that makes teaching advanced computer science constructs (such as closures) very simple.

It’s easy to dismiss the language because of the way it’s been built. Variable hoisting is kinda weird, the fact that if you aren’t careful in the way you create your closures can result in the same variable being “assigned” everywhere and double-equal comparison are a few. Though, as teachers we can help steer our students away from the gross bits of the language and if they encounter them try explaining them. If their eyes start to glaze over simply tell them that it’s the language being weird and show them how to get around it.

Sometimes starting off with a “shitty” language can be the way to go. In the end, if they become interesting in programming they can keep rolling with JavaScript or maybe they’ll be tempted to try out something else. Learning to program should be the goal and helping students do it as quickly as possible is the best way to get them there.


Learning to Love2D

4XpHX

I decided to spend the evening learning another game making framework. I’m still quite happy with Game Maker though getting to see how Lua works in a fun and interesting way sounded pretty neat. Initially I was going to try making some kind of Scorched Earth clone but got all hung up on procedurally building height maps, so I took it down to something super simple; Pong.

I saw that Love2D is integrated with Box2D so I figured I could probably leverage that to make a pong game. It would take care of all the deflections for me, so I’d really just need to switch things around based on some collision information. So really, all thats happening when you hit a paddle is the gravity reverses. While it’s nothing super exciting, it does add something kinda cool to the game. Depending on how you angle your shot you can either make a really hard to hit bouncy one or might even slow it down.

I also noticed that theres a bug which *may* cause the ball to even keep it’s gravity and just come back towards you. Feel free to give it a shot, though make sure you download Love2D and with that installed you can even start making your own love games too!

Download Pong

Controls