Unfathomable Bugs #3: Stringing you along

posted by Craig Gidney on October 16, 2012

Today’s (sortof) bug comes courtesy of Adobe. Thank you, Adobe, this series wouldn’t exist without the generous support of entities like you.

Apologies for the tiny post this week, but with the release of Windows 8 coming up we have a hard deadline crunch.

As you may or may not be aware, one of the many features introduced in ActionScript 3.0 was type safety at compile time and run time. You can write:

var useFrobbing:Boolean = settingsMap["useFrobbing"];

secure in the knowledge that you’ll get an exception if the value retrieved when looking up the key “useFrobbing” is not true or false. Well, that’s the idea at least. Until you notice that useFrobbing is true when you expect it to be false, because settingsMap["useFrobbing"] is the string “false” and the language has “helpfully” done an implicit conversion where only the null string is false.

Ok, ok, it’s a bit unfair to call this a bug. It’s really more of a vestige of ActionScript’s dynamic roots, like the for loop interpreting values of the wrong type as null. Or the fact that dictionaries refuse to store values against the key “hasOwnProperty” (because they have a method with that name, if course!). The behavior is correct, it’s just unexpected (in my opinion) (for a strongly typed language).

View Comments on Reddit


Twisted Oak Studios offers consulting and development on high-tech interactive projects. Check out our portfolio, or Give us a shout if you have anything you think some really rad engineers should help you with.

Archive

More interesting posts (24 of 42 articles)

Or check out our Portfolio.