Sunday, 30 August 2009

ActionScript is not Java!!

When learning a new language (not programming literally a new language), the best thing is not to compare it with other languages and your native language unless they are really very common. Each language has its own grammar, own way to express things and different prononciation. If you try to learn the new langauge base on another one, you will probably end up speaking french as an english men or vice versa. Languages have their own tradition, heritage and culture, which will greatly differ from one to other.

Programming languages are also same. You may object this saying some of them share the same basics, which I also agree (ex. java and c#) but they still differ. If you move from one to another with your native tradions you will never look like a native speaker on your new platform. Its not wrong to use either camel case or hungarian case depending on your tradion but it will definitely reveal where you come from, and for sure you will seem like some one out of the community. Curly braces are also the same, you can use them just after the declaration or the next line but with other classes or methods written by others around you will definitly seem and english men in new york.
I face this issue when i try to teach Flex to someone from Java or .Net background. It is hard to accept your beloved arrayList to be some else acting a bit different although looking quite same. If you are just playing the language then its fine, but if you are seriously interested then here comes the problem. Actually more serious problems are ahead if you do not realize you are in a new world. Here is a great example from Chet who is a Java and Flex expert..

Basically his examples shows the difference of variable decleration and scopes between java and flex.

What do you think this prints out?

            var i:int;
for (i = 0; i < 2; ++i)
var blah:Object;
trace("blah = " + blah);
blah = i;

Or how about this?

            for (i = 0; i < 2; ++i)
var blarg:Object = null;
trace("blarg = " + blarg);
blarg = i;
In actionscript the scope of the variables blah and blarg is function level, which is diffrent than Java. In Java we would expect the reference to be renewed in each iteration. However in Flex since each iteration refers to the same object it is not null anymore after first loop. Which will result an output of;

The first example prints out:

    blah = null

blah = 0

and the second example prints out:

    blarg = null

blarg = null

More details go and check his post! But you might have already noticed him placing the curly braces in the new line which is not a Java tradition but which is actionscript.
Always try to consume as much the culture of a new language, first it will make you close to be a natuve speaker, second you will understand how it works better and finally being multi cultural will extend your ways to think and remember no language is perfect..

Java's tale on OS locales

As a Java developer who is not living in 'english' locale zone, he first thing I do is to change my locale to english whenever I face a new computer. However this is not a natural born reflex I had. Here is the story, why..

It was the year 2003/4 when I started working as an enterprise Java developer in a bank. My first assignment was to solve a problem where the java code which used to work fine on developer computer, failed to connect a network resource. As someone not familiar with the app, I switched to debug mode and deep dive into. After a while I figured out what was wrong. It was just a small innocent character which acts differently in different locales. The character 'i' becomes 'I' when its in caps although in Turkish locale it becomes a totaly different character of 'İ' which is not good for a network address. I don't remember why the app needs to change the case but its clear that its breaking the system.
Later I realised most of the webspehere/rational tool installs and uninstalls fails because of my locale. The funny thing is, since the error is something very unexpected for a developer not familiar with turkish characters usuallly it is not handled well, just displaying an error message of 'nullPointerException' or sometimes not even that. Also when you google the problem nothing pops up since this is a problem occuring only in your locale which very few people should be facing.
After a while I started working in a media company for building JavaME games. I was free to choose my own IDE, so I checked and decide to try EclipseME. After few attempts to install, I decided to google the problem I'm facing. Strangely the only posts stating the same problem were Turkish guys so I didn't even bother to read the posts. Instead I go in to locale settings and change to english, which let eclipseME install smoothly.
We had a group of friends playing Football Manager online. However none of us able to install and run as Football Manager 4 was released. There were no one on the inernet mentioning such a problem but we couldn't able to play. Later I heard that the installer was written in Java, as you can guess it didn't take long to set up our network to play again the new version, and any one willing to change the locale were welcome.
As I move to my next job in Istanbul Airport, I was enough experienced to check the locale settings when I face a strange problem. I remember fixing at least 3-4 times of localization settings. The worst part is, such problems occur may be only once or at most twice a in 1-2 years which doesnt make you think about checking the locale. I remember colleagues to become very suprised when changing the locale when I ask my help and then telling them to check again in snob way ;)
I remember facing much or less the similar problems on Flex which is quite normal. It has jre under the hood and working on top of eclipse but the latest problem which I faced (actually not me, my locale is english) was quite intresting. In mid June I gave a flex course in a bank, and one of the attendee was saying that the flex builder asks the registration key each time although it accepts the key everytime she enters. After trying few times, I dive into property files and saw that flex was able to write the key to the file, however, on startup the builder was asking again. I decided to unistall and install again. Guess what, the uninstaller quited unexpectedly with a message of null. As anyone read so far can guess I changed the locale, reenter the registration key and it has gone..
The problems with locales such as Turkish, are not daily problems but be sure they will appear the moment you expect the less. Working with or on anything related to Java? either set the locale of your IDE to english or just like me set the locale of your OS. I never had any problems or missed any features because of using english locales so far, either in windows, or linux, or macos..