Archive for May, 2012

Re: Please Don’t Learn to Program

Tuesday, May 15th, 2012

This morning Hacker News looked like this:
HN screeny

Jeff Atwood apparently thinks programming isn’t worth learning about, for most people. I think he’s probably right, in the sense that “robots aren’t worth learning about, for most people”. I can think of more examples. “Physics is not worth learning about, for most people”. But that’s rather obvious isn’t it? Why blog about it? Why blog about blogging about it? ;)

Atwood is bashing CodeYear, an initiative to get everyone to learn a little bit about programming. Here’s a retort written by CodeYear’s designer, Sacha Greif. Here’s another retort on Github.

I don’t understand why any of this stuff is worth arguing about. Why does Atwood care what people do with their free time? It seems there are a lot of assumptions being made about the motivations of these aspiring programmers. I see nothing wrong with CodeYear. I see nothing wrong with everyone knowing something about programming (hell, it’ll give me more to talk about at parties), just as I see nothing wrong with everyone knowing a little something about singing. Singing isn’t an essential skill for everybody’s daily life, but neither is math, really, though they both make life more interesting and are worth knowing about. These topics have the potential to enrich our lives, so why not learn about them?

Bang Pre-Alpha

Saturday, May 12th, 2012

I have a new ongoing project, it’s called Bang. It’s a canvas-tag based display list written in Javascript. I’m going to be using it in place of AS3/Flash in my web authoring tool chain. Bang on Github. There are three main elements of Bang that make it special:

Modules

When writing a project with Bang you keep your code separated in modules. Each module exposes a Javascript Object, like a constructor function. The modules object is passed into each module definition, exposing your module to other modules that depend on it. Keeping your code in modules like this means you need only expose one global variable, the list of modules. Any modules loaded this way are essentially sandboxed in that modules object.
You define a module in a similar manner to RequireJS and the AMD:

mod({
name : 'MyObject',
dependencies : [ 'bang::Geometry/Rectangle.js', 'myLib::SomeFile.js' ],
init : function initMyObject(modules) {
function MyObject() {
this.x = 0;
this.y = 0;
}
MyObject.prototype = {};
MyObject.prototype.constructor = MyObject;
return MyObject;
}
});

The module system is another project of mine called Mod. I’ve written about it before. It’s very small and simple and it gets the job done (the job of code separation and later compilation).
Bang adds support for Google’s Closure Compiler to Mod, so once your project is ready to ship you can compile (in a sense), compress, obfuscate and pack your code down into a deployable script or a neato mosquito PNG. I like the PNG method because it’s slightly more obfuscated and adds further sandboxing, but that’s a topic for a later post.

It’s like Flash, but not too much like Flash…

Bang is enough like Flash/AS3 to be familiar, but sacrifices some AS3 similarities in exchange for simplicity and consistency. The complexity in Bang is very small. There aren’t any tricks to make it more Flash-like than it has to be and it won’t protect you from learning canvas operations. In fact, you’ll have to learn about the CanvasRenderingContext2D to do any real drawing. I’m not aliasing those calls and hiding it in a mock Graphics object for you! ;) And you should be learning these new technologies without crutches. Think of Bang not as a set of crutches, but as a set of wings, or at least a hammer and chisel. No one likes masonry-by-hand.

It is fast.

The original pre-alpha version of Bang takes Douglas Crockford‘s extremism literally. There are no uses of the keywords ‘this’ or ‘new’. It accomplishes (multiple) inheritance through special constructor functions that add functions and closures to objects (or creates new ones). This, although a departure from AS3 at first, actually gives projects written in Bang an AS3++ feel. Multiple inheritance is awesome. Private variables are awesome. With prototypal inheritance you lose private variables so by using special constructor functions we can create private variables through closures. These features are awesome, but as Martin Hunt of GameClosure pointed out to me, it’s not fast. Processing time will go up linearly with the number of properties and methods created in the class. This means that if you’re creating a lot of complex game objects every frame tick, the project will likely start chugging. This is not fast. Apps have to be fast! For this reason I started a new branch of Bang that uses traditional prototypal inheritance. This branch will include a dirty rectangles implementation for really lazy redrawing, and I have plans for using WebGL for rendering down the line. Stay tuned!

A tiny demo

Take a look at the source for this div. This is the compiled output of the main branch of Bang. It’s clean, right?!





Follow me on GitHub
Follow me on Google+
Follow me on Twitter