Share/Save/Bookmark Subscribe

Friday, December 31, 2010

Fun with initialization order

Here's something I meant to post ages ago, when I was doing J2ME to Flash conversions, and got caught out by assumptions about the evaluation order of values passed to a method or to initialize an array. It's one of those really subtle issues that had me scratching my head to figure out what had gone wrong in a piece of code.

Consider the following (pseudo)code:
1 2 3 4 5 6 7 8 9 
function evalTest(val1, val2, val3)
{
     print("val1: "+val1+", val2: "+val2+", val3: "+val3);
}

int val = 0;
int arr = { ++val, ++val, ++val };
print("arr: ["+arr[0]+", "+arr[1]+", "+arr[2]+"]");

Now what would you expect the output to be? I had unwittingly assumed the result would consistently be:
arr: [1, 2, 3]
val1: 1, val2: 2, val3: 3

As it turns out, the answer varies from language to language (which is why I got snagged by code working 'correctly' in one language but 'breaking' in another):

Java:
1 2 3 4 5 6 7 8 9 10 11 
int val = 0;
int[] arr = {++val, ++val, ++val};
System.out.println("arr: ["+arr[0]+", "+arr[1]+", "+arr[2]+"]");

val = 0;
evaluationTest(++val, ++val, ++val);

void evaluationTest(int val1, int val2, int val3) {
  System.out.println("val1: "+val1+", val2: "+val2+", val3: "+val3);
}

Result:
arr: [1, 2, 3]
val1: 1, val2: 2, val3: 3
 
Actionscript:
1 2 3 4 5 6 7 8 9 10 
function evaluationTest(val1:Number, val2:Number, val3:Number) {
        trace("val1: "+val1+", val2: "+val2+", val3: "+val3);
}
var val:Number = 0;
var arr:Array = [++val, ++val, ++val];
trace("arr: ["+arr[0]+", "+arr[1]+", "+arr[2]+"]");
 
val = 0;
evaluationTest(++val, ++val, ++val);

Result:
arr: [3, 2, 1]
val1: 3, val2: 2, val3: 1
 
Some others:
C++ undefined:
C# guaranteed to be right to left:

Posted via email from Matt's thoughts

Saturday, December 18, 2010

DSTV Mobile on Nokia N96

With all the marketing Multichoice is doing around DSTV Mobile, I thought I'd brush off the N96 and put it's DVB-H receiver to the test again (previous attempts proved fuitless). This time around it all worked pretty smoothly on the first attempt-if a bit confusingly. Nokia's "Live TV" allowed me to purchase a DSTV Mobile subscription (currently free). I did find though that on restarting the phone after removing and reinserting the SIM, the app had lost my subscription data-no big deal for free promos, but I can see some really irritated users when their paid subscription goes missing. Note that while the app doesn't use 3G to receive the actual TV signal, it does need a cellular data connection to validate licensing (which means no using the service out in the bundus to catch the cricket or rugby).
The app itself is actually pretty well put together, with different program guide views in portrait and landscape, the ability to set program alarms and auto-tuning events, and both fullscreen and windowed (with programming info) views. Parental controls are enabled by default, and set to an age limit of 15, so it's possible first time viewers will have to hunt around for the default unlock code (12345 in case anyone gets here searching for it). Another interesting quirk is that the app locks the video down against both screenshots of content (note the attached shaky cam files taken from my iPhone) and TV out. I suppose I'm not entirely surprised, but this level of lockdown seems seriously ridiculous considering you'll ultimately need a full DSTV subscription anyway when the service goes paid in a couple of months.
The content available in the DSTV mobile package is fairly limited, with the focus heavily on sports, but what's there comes through clearly. I have to say I was pleasantly surprised at both the video and audio quality and the glitch-free nature of the experience, this is no frustrating streamed video. Not being much of a TV watcher, and given the content, I can't say I could see myself paying for the service but I can definitely see the value to avid sports fans and even the 'distract the kids' value of Cartoon Network.

Download now or watch on posterous
ChannelO.mov (1054 KB)

Posted via email from Matt's thoughts

 

Copyright 2007 All Right Reserved. shine-on design by Nurudin Jauhari. and Published on Free Templates

Afrigator