Aha, so I am not crazy! Choose Flash for portable apps. Yahoo says so. 0

For as long as I have been a Flash developer, I have been completely addicted to it. And its only getting better with age. But off late, a lot of people have been eager to prophesize the death of Flash (usually siting poor Flash implementations as reasons). However there are certain features (not counting the wow effect) in Flash that make it a good choice for certain implementations. For one thing Flash Player (esp greater than 9 which 98% of the users now have) is much faster in processing data than javascript, especially on older browsers. Another reason is that a self contained swf file is a lot more portable when moving from one environment to another. In today’s world of Facebook widgets, OpenSocial containers, etc etc, deploying a swf is a lot easier than packaging a suite of javascript files. Actually a lot of those containers won’t even let you deploy JS on their servers and force you either to use an html extension like FBML or use an IFrame (and again there are limitations set on where those can appear on the sites). So it was really heartening to see that officially be posted on the Yahoo Developer Networks blog by Jonathan LeBlanc, Senior Software Engineer / Technology Evangelist from Yahoo. So do give it a read and use that as ammo if you are in another one of the “Why Flash” conversations.

The post can be found here.

Also take a look at the Yahoo Open Strategy (Y!OS)’s Flash SDK here (Yahoo has only released a Flash and a PHP SDK).

Go Flash !

Mixing up OpenPyro and Facebook: FacebookTV 3

For the last couple of weeks, I have been working quite a bit more on OpenPyro. Writing a new UI framwork in a vaccum almost never works, so I needed an app to build using OpenPyro. I had some Facebook API code handy so I figured I’d try something with that. So here is a screencast of the app as it is right now. The application uses Facebook’s desktop api to get all the friends of a user and their favorite TV and Movies. Then I group the shows/movies together to see what the most popular of them are and sort them with the most popular ones at top. The data is rendered in an OpenPyro chart component. The TV and Movies are in two different Horizontal Chart components and sit inside an OpenPyro container called SlidePane. SlidePane extends the OpenPyro ViewStack (which is very similar to the Flex ViewStack) and automatically handles sliding between different views (each being an OpenPyro UIContainer). Clicking on an entity does a show/movie lookup from Fancast.com, and also lists who among your friends have added the show/movie as their favorite. The BarChart below is segments those friends by gender or by relationship status ( I have to say, the Facebook API is pretty rocking, and I can segment the data on a variety of axes. )

Here is the awesome-est image of it all:

FacebookTV filesize

Yup. The whole sucker is about 60K. And that includes Labels, Buttons, Lists, ComboBoxes, Layouts, Painters, Containers, etc etc.

So here is the show:

OpenPyro is still not ready for a general release yet, but its coming along pretty sweetly.

Comments welcome.

The great AS3/AS2 debate: Is it slower to work with AS3 than AS2? My take: A bit 7

Mike Chambers, Principal Product Manager for developer relations from Adobe, has been pinging the Flash community about whether AS2 based development is faster than AS3 for Flash projects. Having spent a long time in both languages, I thought I would post my 2 cents on this blog. So my answer is: Yes. Of course I'll qualify my statement by saying that 1) There are a lot of capabilities in Flash 9+ that are amazing but I want to disconnect the language (pure syntax) from what it enables and 2) This post assumes you are as comfortable with AS3 as AS2. I am not factoring in the learning curve for a new language, which happens anytime there is a drastic change.

AS3 can use some help. Let me list out some reasons why I say that:

  1. Loading XML is a complete pain
  2. Calling an external URL is AS2 was simple (although having to use delegate because of the lack of proper closures was retarded). The code was something like this:

    Actionscript:
    1. var xml:XML = new XML()
    2. xml.ignoreWhite = true;
    3. xml.onLoad = function(success){
    4.       if(success){}
    5.       else{}
    6. }
    7. xml.load('doc.xml?foo=bar')

    Very readable, plus all errors were available in one check. Lets compare that to AS3:

    Actionscript:
    1. XML.ignoreWhite = true;
    2. var urlLoader:URLLoader = new URLLoader()
    3. var urlRequest = new URLRequest('doc.xml')
    4. var urlVariables = new URLVariables()
    5. urlVariables.foo = bar
    6. urlRequest.data = urlVariables
    7. loader.addEventListener(IOErrorEvent.IOError, onError)
    8. loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
    9. loader.addEventListener(Event.COMPLETE, onComplete)
    10. urlLoader.load(urlRequest)

    How verbose is that? I am still trying to figure out why every request needs a URLRequest object, seems unnecessary. just calling urlLoader.load("data.xml") could automatically create a URLRequest object, if you ever want to examine a request post it being called. Another huge problem is most developers I know dont actually add the error event listeners, just cause adding it is so tiresome. So when an error occurs later, they are usually clueless to what happened (was it a code bug or did some http call out just did not work?).

    The URLRequest param for navigateToURL seems another one of those requirements that seem unnecessary.

  3. Whoops, forgot my addChild
  4. I think this is where I have lost countless hours, I would create a sprite, and set its properties, but forget to add it to the stage...and then spend too much time to figure out what did I do wrong. The only way to create a new UI element in AS2 was by referencing an already added MovieClip (remember my_mc.createEmptyMovieClip() ?). I would love to have a createAndAdd function in DisplayObjects that becomes the default way of creating new Sprites.

  5. Dynamic drawing: The graphics object
  6. Drawing in AS2 was simpler: MovieClip.lineTo(....). In AS3 it has to be on the graphics context of the DisplayObject (mySprite.graphics.lineTo() ), but why? There isnt any other context to draw on, and the graphics context isnt swappable, so why do I have to type that in?

  7. No numeric depths
  8. In AS2, you could set explicit depth numbers to elements and reorder elements under those depths. So for example, if you were writing a button control, you could set the label field up on depth 1000 and keep swapping out the children under it. In AS2, you have to track where in the display tree your element is.

  9. useHandCursor vs ButtonMode + useHandCursor
  10. I dont know what buttonMode does besides actually allow me to useHandCursor property, which I have to set anyway

  11. No onReleaseOutside
  12. This one also is weird. The way we now have to do an onReleaseOutside is via listening to a stage click event. But wait, you may not be on stage yet, so you need to check : if(stage), and also write an event listener to the addedToStage event. Verbose.

  13. addEventListener vs. onRelease
  14. onRelease (and similar "on..." functions) is not a bad default hook to have. Considering how often we write these functions, having a quick shortcut to the action was nice. Not that I am saying the event model is bad, but I end up writing a lot of addEventListeners and removeEventListener throughout the code.

I think overall, when I look at an AS3 file, it just seems longer than AS2 code used to. I think everything needs to be very explicitly set in AS3 with no smart defaults. Maybe that'll change in AS4 now that we no longer care for the ECMA spec ;) . There are a lot of improvements in AS3 as well though, like actually having private and protected namespaces, but I am only listing out my pet peeves here hoping Mike takes note :) . Flash is an amazing platform, and I love what it enables me to do.

Isn’t quality code a feature ? 9

I have had a few conversations with some fellow developers here and there (most often with Mat) around code quality, and sometimes I get really frustrated to see what passes for "Good enough for now" code. In user interface development, its very easy to confuse all work with all visually displayable features. But when you are going to live with the code for a while or this code is going to be the foundation of later features, how can you not track code quality?

And of course there are extremes to that argument. I have worked with enough wannabe-architects who want the code to be pristine and who would much rather write their perfect piece of software no matter what the cost (in terms of time, features dropped or developer-pay) is. They should be tarred and feathered cause they weaken the valid calls for code quality.

But there has to be a middle ground here. The problem is well-written code is hard to quantify. Features are blessed with visibility but architecture isn't. I had a conversation with a friend yesterday on how I prefer being a developer to a designer since design is so subjective, and what I might think is wonderful design may be pooh-poohed by someone else (worse, my theoretical manager), but code either works or it doesn't and thats instant feedback.

Software architecture or "well-written code" seems to suffer from the same problem of subjectivity as design to some extent. And if you are fortunate enough to actually have a conversation around code quality (and I dont mean in the theoretical sense but you actually sit down and review what you have written), its lack of visible benefits to the product makes it one of the first things to be dropped when trying to make deadlines.

How do you quantify code quality then? As a developer I can tell you it has real returns. In my (Flash) world it sometimes translates to faster load times, less taxing of the CPU, smaller number of classes to be maintained, but its really hard to measure. How do you say the swf weighing 300k is worth the extra couple of weeks than a swf weighing 600k that was never written but would have if checks on code quality weren't there. How do you measure against something that never existed ! Worse, how do you track that when there is no feature that maps to lighter swfs ?

And then there are the the really invisibles: dead code paths within code, extra classes that you dont use or are so badly written that they are such pain to work with that other developer on the project just writes new classes with the same functionality? How do you check such things? How do you justify investment in tools that enable high quality code ?

Heck, if you had to justify version control, how would you? Thank God some things like that dont have to be justified anymore but when will that stature be given to tools like Review-Board. Is code quality just a developer itch ?

Do you track code quality ? How ? Do you use any particular tools ? Do you have coding standards ? Please share your thoughts here, cause I am really curious.

Does good code-base just accidentally happen to get written or is there a process to get to it ?