Dangerous code geeks

I recently read through Peter Seibel’s excellent Coders at work, and if you’re a developer of any sort, I reckon you should too. Three interviews in the book stood out to me, though they are all excellent; Jamie Zawinski, Douglas Crockford and Brendan Eich.

Jamie’s interview cements the notion of a duct tape programmer; A developer who understands that in real life, the work is WORK, and problems need to be solved pragmatically for deadlines to be met, paychecks to be cashed in and children to be fed. He’s an autodidact, he has worked with people “smarter” and “dumber” than himself, but none of that fazes him. It’s work, and he does it well. The goal is to finish something that works according to expectations.

Reading this interview I personally felt a huge relief. I’ve worked with others from designers who can barely understand why curly braces exist to having my code reviewed (and panned) by university computer science graduates. On one end of the spectrum, I am a wizard, where I enable things others can’t even understand is possible. It feels fantastic. On the other, I’m a heathen. Why all these singletons? Why no dependency injection? Why not this? Why not that? “Over there”, I don’t know what’s what.

But, you know, for the most part, I simply do what is necessary to meet the demands within the alotted time frame, and to be able to adapt quickly when changes are inevitably requested. It makes for code that is often ad-hoc and cobbled together. I have never regretted this; My work can turn on a dime. I refuse to let someone geekier than me kill my personal joy in programming; Creating things.

Compared to Zawinski, Crockford and Eich are almost polar opposites, and their interviews, side by side, read like an argument and its rebuttal. Crockford is, from what I can tell, a programming “geek”. We should all know the geek-nerd-dork-dweeb venn diagram by now:

Crockford and Eich disagree strongly on the ECMAScript 4 specification, which Eich designed in committee with Adobe and others. ECMA4 is, as we know, ActionScript 3. Crockford spends his interview first acknowledging the problems of ECMA3 in its JavaScript implementation; Reliance on a global object and resultant issues with the security model. Beyond that, JavaScript is apparently a godsend by virtue of being a true “lambda language”.

Let’s digress for a minute or two.

“Lambda”

If you’re not familiar with this incredibly geeky term, in terms of ActionScript and JavaScript a “lambda function” is best understood as a function that isn’t declared a class or instance function but rather kept in a variable and passed around, or just called right then and there and then left to garbage collection. Here are some examples:

//Anonymous function simply returning a value
var n:Number = function():Number { return 20; } (); //n is assigned the value 20
var a:Array = [1, 2, 3, 4];
//Anonymous (lambda) function creating and calling an anonymous (lambda) function of its own
var sum:Number = function():Number { var n:Number = 0;  a.forEach(function(value:Number, index:int, array:Array):void { n += value; } ); return n; } ();

//Function returning a lambda function
function getFunc():Function {
return function():void {trace("Hello lambda")};
}
getFunc()(); //crazy lookin' but completely valid

As you can guess, lambda functions are hugely powerful. Passing references to functions around with adjustable scope is a fantastic tool, and though I personally feel like anonymous functions drastically reduce the readability of the code and introduce complexity where reusability should be preferred, I still use them from time to time.

Back when I first started learning object oriented programming, it was in Flash 5 ActionScript 1, which adhered closely to ECMA3. I wanted to learn game programming, and here was a language that didn’t offer almost any of the terminology every book and article I read was referring to. Classes, inheritance, interfaces, none of that. Flash developers struggled to adapt to a market that demanded larger and more complex applications in a language to which the closest parallel was one that barely could scale an image or change the value of a form field.

The Flash community, like the JavaScript community, became home to some seriously clever hackers. There was a lot of crossover as coders in either camp struggled to wrangle some order into the languages they were bound to. Soon, I was taught how to create classes in Flash, but our classes were simply anonymous functions.

var obj:Function = function():void {
this.bool = true;
this.name = "MyObject";
}
var myObj:Object = new obj();
trace(myObj.name);

This approach necessitated judicious understanding of scope, and resulted in more this-keywords than you ever see in modern programming. Yet we had no inheritance. I don’t even want to write about the boring, convoluted boilerplate code we had to write time and time again to approximate a simple “class Foo extends MovieClip”. Everything that now is nice and orderly was a hack then.

Of course there were boons still. We grew accustomed to manipulating the prototype chain, by which we could give any object new properties by way of manipulating its prototype. For instance.

MovieClip.prototype.flipX = function(){
this._xscale = -1;
}
anyMovieClip.flipX();

In retrospect, was jerking off the prototype chain worth the syntactic mess we were dealing with? Personally, I would rather forget those years. Learning was slow, development was convoluted, and mastery always seemed far away. It was difficult to settle into a comfortable groove. On larger projects (I worked on an AS1 MMO at one point) code maintenance was almost completely unbearable. Reusability was a joke.

Long story short, 2 years into my career as an ActionScript developer, I had an ulcer, and I had gallstones the size of my thumbnail (bybye gall bladder). The stress and discomfort associated with AS1 development made me swear off the industry altogether at one point. It took nearly 6 months to reel me back in. Thank god I was met with AS2 and concessions towards traditional coding practices. When AS3 landed, my world snapped into place. Now I could work. Thank you ECMAscript 4.

Mommy, don’t make me go back there!

Reading Crockford’s arguments for ECMA 3.1 as he simultaneously decries the dominance of C++ over Eiffel is terrifying, simply because the man has real power. He’s a JavaScript evangelist (of all things) who, to my ears, sounds more enamored with the technicalities and THEORIES than the real world applications. He’s clearly intelligent, clearly obsessive, and clearly out of touch with the fact that thousands of people make their living using and loving a programming language he condemns for its “complexity”.

I’ll reiterate my strong respect for the JavaScript community; They have taken a language that literally made me cough up blood and have to give up fatty foods and wrangled it into shape with frameworks like jQuery and Prototype which finally allow developers to do real work. But this doesn’t change the fact that the fundamental language was painful enough to necessitate this sort of wrangling. Hell, jQuery syntax barely resembles JavaScript. As CSS3/JS/HTML5 looms ahead, the notion that the future of the base language is controlled at least in part by people who actually LIKE the bits the community has done its best to override. As a consequence, the Flash community as well are collateral damage as Adobe need to defend their “flawed” language.

I can’t recall the ActionScript community complaining about the complexity or verbosity of the language itself. We have our issues more with the lack of complexity, such as lack of abstract keyword, or in some cases with the verbosity of the flash framework, ie addEventListener, but are we really bothered by how “complicated” it is?
Anyone wanting the loose anarchy of AS2 can switch off strict mode and prototype and dynamic type and lambda the shit out of anything all they want.

So the argument seems to be then that those of us enjoying the complexity and verbosity are somehow wrong.

And that’s the crux of the problem for me. Programming languages should be judged by their merits, not their subjective aesthetic qualities.

After years of ECMA4, and a blooming, prosperous Flash community being the testbed for that language, how can we call it wrong?

3 thoughts on Dangerous code geeks

  1. AS3 literally changed my life. I moved from being a not especially good designer who hacked code, to a proper programmer who read programming blogs and books and actually cared about the quality of my code. It created a black and white programmer/designer split though, where there used to be a nice smooth gradient. We had to tell a bunch of people at the design agency where I worked to stop leaving their hacky code on our timelines, thanks.

    Statically typed languages, used properly, create self-documenting APIs, with invaluable autocompletion and validation, easier debugging, and generally don’t require unit testing. What’s not to like!?!

  2. Those graduates really hate the Singletons don’t they?! DI is nice but get’s bothersome quickly if done manually. Frameworks like Robotlegs automate it, but at a small performance cost. Then again such frameworks aren’t the end to all. (I wouldn’t want to use RL with all it’s overhead for a game development where I need max. performance.).

    Haven’t read the book, but according to the diagram wouldn’t Crockford rather be a Nerd? I’d let my hands hack off before I’m forced to go back to a dynamic typed “spaghetti” language like AS1!

    “can switch off strict mode”

    I think many of the programmers whose open-source code libs and framworks I sometimes fetch via SVN/GIThub and that show up tons of errors & warnings in FDT must be doing this! How else would the compiler progress code that has undefined objects etc.?! ;)

    Time to go learning haXe …

  3. I use RL all the time for my games… not for the main game itself, (I have one mediator that sits on top of the game but that’s it), but I use it to tie the entire application together:

    - Intro View
    - Home Screen
    - Story View
    - DialogManager
    - HighScore Board
    etc

    It’s doesn’t need to be a performance drain if you do it properly.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>