Inheritance is evil, and must be destroyed

When I built Animator.js, I got some flack for suggesting that inheritance is not a Good Thing. Keen to avoid a holy war I restated my position to ‘inheritance is often useful, but more often overused.’ Over the last few months I’ve been trying to figure out exactly when it should be used, and have concluded – at least for the kind of systems GUI developers build – never.

Continue reading Inheritance is evil, and must be destroyed

The inamo mouse system: a hacktastic story

This is the (long) story of how inamo became arguably the world’s first two-mouse Flash installation. If you enjoy the geeky details of programming projects, this is for you.

Sometimes a single sentence in a specification can balloon into a task as daunting as most of the other sentences put together. This is the story of one such sentence.

Continue reading The inamo mouse system: a hacktastic story

eval() considered useful: code generation in JavaScript

If ever a feature of JavaScript was considered harmful, it’s eval(). It’s so commonly abused that if I’m interviewing a JS web developer, I usually ask something along the lines of “what is eval(), and why shouldn’t you use it”. It’s so commonly abused that Yahoo JavaScript architect Douglas Cronkford considers it “evil”, and his JavaScript style checker JSLint reports use of it as an error.

People dislike eval() because it’s perceived to be slow and insecure. In this article I describe a way to use eval() to make your application faster.

Continue reading eval() considered useful: code generation in JavaScript

Animator.js: JavaScript animation library

View animator.js on GitHub

Community translations:

Animator.js was a library I wrote back in 2006 to handle animation on web pages. For a time it was quite ahead of the curve: It was the first library to feature CSS morphing - the ability to smoothly transition between two styles defined as CSS classes.

The world of JavaScript has moved on a lot since then. Animator.js has now been incorporated into most of the major JavaScript frameworks, either by directly porting the code (Animator.js is released under a BSD license that allows people to do this) or by borrowing the techniques. In particular, CSS animations produce better results and use less processor power. For a modern library that exposes CSS animations through a similar API, I recommend jQuery.Transit.

I'm keeping this page up here for historical interest, because it's written in a tutorial style that will be appropriate if you want to learn how to create programatic animation in any language.

Thanks to Tim Stone, Kaspar Fischer, Clint Priest and other developers who contributed feedback and features.

Continue reading Animator.js: JavaScript animation library

Proper private constructors for ActionScript 3.0

Here’s a useful tip for Flash and Flex programmers. ActionScript 3.0 is great, but has no Singletons.

Samuel Agesilas has a solution that successfully prevents subclasses from calling the constructor using super(), but it doesn’t prevent other code from creating new instances of a class with new

Therefore I present to you a crafty hack to make a constructor truly private: add a required argument to the constructor, which must be set to a secret value that is only known to the class:

Continue reading Proper private constructors for ActionScript 3.0

How to debug JavaScript in Internet Explorer

I want to share with you a trick for getting a world-class debugger for free in IE.

JavaScript debugging in Visual Web Developer Express

Some background: users of Visual Studio have long known that it comes with an awesome debugger, probably the best JavaScript debugger there is (though Firebug is catching up fast). Whenever you get a JavaScript error, Visual Studio can connect to the Internet Explorer process and start debugging. You can pause the execution of the code, rewind and fast-forward execution, modify data held in variables and get notified when specific variables change in value. Once you’re used to it, coding without a debugger makes you feel like a blind man in a dark room looking for a black cat that isn’t there*.

Continue reading How to debug JavaScript in Internet Explorer