SWX

March 31st, 2007

I won’t lie, I don’t really care for data interchange formats (or data exchange formats, or standardized format exchanges, whatever you want to call it), so that’s why my eyes glossed over while reading about Aral’s SWX project. This is all despite the fact that I myself have actually helped create what could be called a data interchange format. Now after all the drama surrounding spewed forth I decided to give it a look and you know what? I’m impressed. In theory anyway.

I love the idea of leveraging Flash to produce faster results because of my long-standing obession with speed. I like SWX because it’s the closest thing to basically encoding data directly into Flash. Since some serialization always has to take place, why not serialize strings or arrays directly into a SWF? I can’t speak for Aral’s implementation, but to me it’s clearly one of the better ideas when it comes to Flash-specific solutions. If you have control over the client and everything server-side then the your solution need only be reliable. SWX offers real advantages to those who want them.

Since I’m one of the developers for FZip, which arguably an alternative format, I’d like to note that FZip and SWX are two very different things. FZip is intended to transfer files, not data (like an array or a string), although both systems could arguably do each other’s job, they wouldn’t be very good at it.

I’m ending this post with a couple quotes from Aral’s hilarious angry pro-SWX rant. Keep in mind I actually like SWX and wish to see it evolve, I just find these little tidbits very humorous when quoted out of context.

  • WTF? Who died and elected you Pope, Mr. Hultberg?
  • You see, Flash developers are an ignorant bunch who live simple lives.
  • He is the white man come to educate the natives with the Word of the Lord.
  • [Humans are] an unpredictable, complex creature that may just be scratching his balls with one hand as he uses your lovingly crafted interface with the other while simultaneously devoting 73% of his attention to Carmen Electra’s rack in the trailer of I Want Candy that’s blaring on his TV screen.

Update: Hardy-har-har

More Actionscript One-Liners

March 27th, 2007

I’ve been having some fun working out new speedy lines of code using operators

// if str is blank, pass an alternative string
return str || "str is blank";

// if obj isn't active, return null
return (obj.isActive && obj) || null;

// If num is zero, return "1" instead
return num || 1;

// If num is zero or not a real number (including NaN), return "1" instead
return (isFinite(num) && num) || 1;

// If num is less than 0 or not a real number, return "0" instead
return (isFinite(num) && num > 0 && num) || 0;

// add an entry to a list that is created if it doesn't exist
(arr || (arr = [])).push(entry);

Anybody have other ideas?

Apollo

March 19th, 2007

The public alpha is out. I awoke suddenly in the middle of the night for no apparent reason, only to find that Apollo had been released… almost as if it was calling to me. 😉

It was fairly easy to port my current project to an Apollo app and I was pleased to discover that you can create Apollo “air” files (installers) on Linux. Not that this matters since “air” files are just zip files, so I could probably make an “air” creator myself. The Apollo runtime and debugger aren’t available for Linux, which is understandable, although they should probably find the time to port it later if they want Apollo to be taken seriously. It doesn’t matter much to me since my project works under multiple circumstances (Apollo, Flex, Flex-less Actionscript) and I do my debugging under an simpler environment.

So far I like Apollo, but it’s easy for a Flash developer to like Apollo, what about everybody else? With all the (somewhat undeserved) attention towards Web 2.0 sites, I wonder if anyone will even notice Apollo. It’s still a nifty idea anyway, and there might be a niche out there just waiting for Apollo to come along.

Faster Actionscript

March 17th, 2007

I’ve long been mildly obsessed with getting power out of Actionscript. These days Actionscript is fast enough that I can code with less time spent optimizing, but I still like writing code I know is faster than its more readable counterpart. I never thought this line, one I use frequently, would ever be trumped…

var value = obj ? obj : (obj = new Something());

It’s very straightforward, right? If obj doesn’t exist, it is created, and a non-null value of obj is always passed on. How could it get any better?

var value = obj || (obj = new Something());

That’s how. I spotted a similar line while checking out Papervision’s source code, the only library I’ve ever seen where the obsession with optimization is greater than my own. This line only offers one less operation, which is practically nothing, but it’s still very interesting especially when there could be real advantages to using them in a long series. You can do similar tricks with a && operator. These two lines do the basically same thing…

var value = objA ? objB : null;
var value = objA && objB;

A series of && operators returns the last statement if all previous statements are non-null. A series of || operators returns the first non-null statement. I always thought those operations converted everything into boolean values, but they don’t, they pass on values based on their equivalent boolean values. But that’s not all the interesting things I’m leeching from Papervision, there’s also the best lazy array iterator I wish I thought of…

var p, i = list.length;
while (p = list[--i]) p.doSomething();
// or
var p, i = 0;
while (p = list[i++]) p.doSomething();

This line reminds me of my speed-obsessed days. It’s similar to a technique I’m using now, but it has a flaw (feature?). If the list changes then entries may be skipped or run more than once. Regardless, it’s very stable and probably the best way to handle things as long as an entry can be run twice or skipped without messing up everything. It probably doesn’t have a speed advantage over this… (Update: Looks like the following method is slightly faster as long as you don’t need to access list[i] more than once)

var i = list.length;
while (i-- > 0) list[i].doSomething();

But it stores list[i] in a variable, which allows static typing to be used, and makes sure the variable is non-null beforehand. Too cool.

Update: Did some basic speed tests. Papervision’s method beats out a “for each” loop every time. The “while (i –> 0)” loop has an advantage as long as list[i] is accessed only once. Might just be my computer though.

I'm Blocked in China?

March 6th, 2007

You read right. According to the Great Firewall of China I am blocked from Chinese eyes. Apparently this isn’t absolute, and you can be partially blocked, but I’m having a hard time understanding why I’d be blocked at all. A quick check of my neglected Google Analytics account didn’t reject the idea. I get massive amounts of Asian visitors, but the amount of Chinese visitors is low these days. Are there just less people in China interested in my site or are they not allowed? The idea that someone in China could see me as a bad influence is very strange but at the same time, pretty cool.

Update: Maybe not, Carol (who commented on this post) sees my site just fine from within Chinese borders. Oh well, my days of unknowingly subverting China are over.