Thank you Apple, May I have another…not! 5

Word on the street:

The Daring Fireball post talks about how Adobe is screwed now. I dont know about the financial implications, but if nothing else, the CS5 cross compiler has definitely proven how the exclusion of certain runtimes has nothing to do with performance but is a pure power play.

In other news, I am now looking for the cheapest way to get a Nexus 1. Could Adobe and Google please set up something for us refugees from the big A dictatorship?

Google AppEngine App issues on Snow Leopard 3

I always seem to trip up on these language version issues. I spent way too much time on this so, as usual with such things, I thought it was worth a post. Early this week I upgraded my work machine (MacBook Pro) and the new machine came packed with Snow Leopard. Today, I had some free time so I figured I’d modify this “lab” project that a few of us worked on at Comcast Interactive Media a few months ago.

I use the GoogleAppEngineLauncher application to start/stop the apps and it seemed to launch fine once I had the code checked out from SVN. However one part of the application, which loaded some remote data and stored it in the DataStore didnt seem to work anymore. Stilling digging through what could have gone wrong, I ended up isolating the issue with the invocation of urllib2. Looking through Google’s documentation, I tried switching to URLFetch which fixed that part. But a couple of lines later, I tripped over another issue. This time the error was a lot more explicit with some message mentioning a missing __init__ in the 2.6 version of Python. So I tried switching the Python location in the /usr/bin/python to the 2.5 version but that didn’t work. Turns out to switch the Python version on the launcher, you have to set the value in the Preferences panel for the application as mentioned here. Ta daa! That worked.

Note, if you are using the command line dev_appserver.py script to run your application, check out this post here

Dispelling the FUD! Silverlight is NOT on the iPhone! 5

This is crazy, do any of these bloggers actually read the announcements? My Twitter/RSS-feed streams are clogged with Silverlight on the IPhone items like here, here and here, and thats just not the case. So lets please get the facts right: Silverlight IS NOT on the iPhone. Or rather the browser plugin called Silverlight isnt.

Here are the facts. Microsoft User Experience Platform Manager Brian Goldfarb stated:

“We’re translating the content to support the MPEG2 v8 [decoder] format that the iPhone format; we’re moving it to their adaptive streaming format. So it’s the same IIS smooth streaming content, the same server, the same point of origin, but now I can get that content to play without any code changes, without any real work, on the iPhone. That’s the critical thing for our customers.”

Microsoft, Adobe and Apple have all proprietary adaptive streaming formats. For a better understanding read this article on Apple’s adaptive streaming on NewTeeVee.

Now in all honesty, thats cool. So you place a bit of video that silverlight can adaptively stream and if an iphone requests that, IIS will handle that as well. I am not sure but Adobe’s solution may need the Flash Communication Server to step in. But the perception of “free” only works if you are resigned to use IIS anyway, which I am sure a lot of Silverlight shops are anyway. But there is that difference.

However the titles of the posts I read and the followup comment are so WRONG. Silverlight isnt on the iPhone, video that Silverlight could play now plays on the iPhone.

Crazy!

Migrating to Java 1.6 on a Mac (Warning: Flash CS3/Flex Builder/Eclipse wont work with it) 7

[Update: Changed the title, added "on a Mac" because everything mentioned here is applicable to that platform alone]

After not looking at it for 4 years, today I started playing with Java again for a new open source project called RedCar, a programmers text editor that is now being ported to SWT and JRuby. Mat is getting pretty involved in it and he got me curious about the project. However to actually get it to work I had to get the Java 1.6 code to compile on my Mac which was a little tricky. Here are some notes from that.

The JDK 1.6 was part of one of the recent Mac Software updates but what I found out was that the update does not actually change the default JDK/JRE for the system. The first thing I did was to change the symlinks for java and javac as mentioned on this post. That seemed to work and calling java – version and javac -version seemed to return the correct versions, but running the build file still did not work. After a few other attempts, including trying the Java Preferences Application without any luck, I finally found this post that basically talked about the CurrentJDK symlink that apparently my build.xml was using (and was still pointed to JDK 1.5). That seems to have worked.

One last thing. Apparently Eclipse (and Flex Builder which is built on top of Eclipse) doesnt work with Java 1.6 on a Mac. As this post suggests, you may have to make a change to the Info.plist for the application to make it run with Java 1.5.

[Update] The Flash CS3 IDE doesnt work with 1.6 as well, so I am reverting back to 1.5 for the time being.

Object Oriented JavaScript Techniques 4

This post is in response to a couple of conversations I had with some friends around OOP in JavaScript. Over the last couple of months I have gotten really deep into the language with JQuery (which is a fantastic library by the way) so I thought I’d quickly list some techniques I have been using to structure my JavaScript code.

Creating a very simple class with an instance variable:
JavaScript has no concept of classes but they can be mimic-ed by creative uses of the Function object. So for example this is completely valid:

var vanillaFunction = function(){
	this.name = "vanilla"
}
var instance = new vanillaFunction();
alert(instance.name) //	vanilla


In the above case, “name” becomes an instance variable of the vanillaFunction class.

Constructing instance methods

var vanillaFunction = function(){
	this.name = "vanilla";
	this.sampleMethod = function(){
		return "SampleMethod was called";
	}
}

var instance = new vanillaFunction();
alert(instance.sampleMethod())

Under the hood whats going on is that the JavaScript interpreter is attaching the Function objects to the vanillaFunction’s prototype chain. So to add another function, we can append that function right on the prototype:

vanillaFunction.prototype.getName() = function(){
	return this.name; // returns "vanilla"
}

Note that these functions have access to the name instance variable defined in the main vanillaFunction class.

Creating class variables and methods (kinda):
Since all functions are essentially Objects, variables can be tagged on to the function object and then referenced as static class variables.


vanillaFunction.classVar = "some value here";

Same way, static functions can be created as well:

vanillaFunction.staticFunction = function(){
	alert("static function called");
}

However it should be noted that the static variables and methods do not have access to each other unless explicitly passed during invocation. Personally, I hardly ever use this and prefer static classes as shown below.

Creating Static classes:
A static class is one you can never create a new instance of. For example, instead of having static methods in a JavaScript class, you can create a static class by declaring your functions as variables on a pure JavaScript Object. This method can be used for example for creating a class of utility functions:

var utils = {
	trim:function(str, numCharacters){
		return str.substring(0, numCharacters);
	},

	log:function(msg){
		if(console){
			console.log(msg);
		}
	}
}
var s = utils.trim("Good day to you sir", 4);

Creating classes with JQuery
To create a class with JQuery, we use the jQuery.extend function which pretty much adds the instance methods to the prototype chain as we saw before:


MyClass = function(){
this.title = "MyClass";
};

$j.extend(MyClass.prototype, {
toString:function(){
return this.title;
}
});

Events:
Even though the ECMAScript specification defines events and how they work, they are not implemented consistently across browsers. The JQuery event system is much nicer since a) it works cross-browser and b) the event source doesn’t necessarily have to be a DOM element.


var obj = {name:"SimpleObj"};
jQuery(obj).bind("objectChanged", listener);
jQuery(obj).bind("objectChanged", listener);
jQuery(obj).trigger({type:"objectChanged"});

In the above example, we are binding to a custom event of type objectChanged. Usually, I access the event type as a static class variable:


var CustomEvents = {
OBJECT_CHANGED:"objectChanged";
}
jQuery(obj).bind(CustomEvents.OBJECT_CHANGED, listener);

That covers pretty much the basics oF OOP in JavaScript. A lot of metaphors (like private/protected/public accessors) may be missing here but I havent really found that to be too much of a problem. These metaphors have made my code a lot more manageable.

Further reading:
John Resig’s list of lessons in advanced JavaScript