A Coding challenge

Just finished writing an article called “Polymorphism Without Interfaces “. I challenge you to review and explain the code below (it ‘s written in ActionScript 3.0) :

for(var i:uint = 0; i lt; workers.length; i++) {

var p:* = workers[i][ “increasePay “];

output.text+=p==undefined? “no luck “:p(5);

}

The person who writes the best explanation, will get a free copy of my e-book “Java programming for kids, parents and grandparents “. I ‘m sure plenty of people understand the syntax, so I ‘m looking for an explanation of WHY it ‘s written this way.

I also want to see a million Flex developers in three years

It “s 5:30 PM, and I “m tired. When I “m tired, I pick a topic and blog for 30 minutes or so, and this helps me to relax. Today, I “ll unload some thoughts on the situation with Adobe Flex, and why I want this technology to succeed (Adobe has an ambitious goal of having a million of Flex developers in three years).

I “m not going to annoy you with all reasons of why I think it “s going to be hot. Let “s just have a more generic discussion about a success of a programming language in the business world. So kids who become exciting just by creation of a cool little thingy in Flex or Flash should not read this blog. I “ll start with throwing some random thoughts at you, and write a brief summary at the end, if needed.

1. The most popular programming language is Java: 5 million PROFESSIONAL developers use it.

2. I have 4,999,999 competitors. No good. But I know Enterprise Java pretty well, which is good.

3. I also know Flex pretty well. There is almost no competition in this field today. I work for a small company of RIA experts (Farata Systems), our rates are not low, but very reasonable for what we deliver. There is not too many Flex projects at this point, but it “s more than we can handle.

4. You “d expect that I would want to keep the status quo since the demand for our skills is pretty high. Wrong! I want more people to learn Flex.

5. When I recommend to my clients using Flex as a front end tool, the first question they ask is “Who else is using it? rdquo;. This is a very important and pragmatic question. Development managers have enough stress already to take chances and switch from an established platform to this super promising dark horse.

6. A development manager thinks, rdquo;I like Flex demos, and it seems to be a pretty solid platform that perfectly fits my needs. Yakov knows what he “s doing, we can start a pilot project, but what if three month from now he “ll have more lucrative offer from another client and quit? IS THERE A POOL OF SKILLED FLEX PROGRAMMERS? rdquo; There are lots and lots Java developers out there, that “s for sure.

7. And the development manager is right. He has his own agenda and career plans. He would not mind using bleeding edge cool technologies as long as his career is not in jeopardy. That “s why I want to see lots of Flex programmers .

8. There was Adobe and there was Macromedia. Their merger was made in heaven. But the honeymoon is coming to an end, and it “s about time to start heavy marketing of Flex.

9. Someone said that the crew of any software company consists of two parts: sales and sales support. Adobe Sales support (a.k.a. technical evangelists) works fine. Today, Flex evangelists are actually selling Flex to enterprises. It “s about time to inject some serious cash into sales force and advertisement.

10. Adobe should give away Flex Builder to college students for free. In a couple of years they will join the work force armed with the right understanding of what “s the right tool for RIA development and will keep selling the product from inside. Their minds should not be poisoned by free AJAX. This strategy worked for Java, and there is no reason why it would not work for Flex. Charging students $79 for Flex Builder is wrong ndash; they do not have enough money for partying. Have mercy.

11. So why don “t I afraid of competition? Because I am an early adopter. Students are still partying, and India is still asleep. My Flex+Java+business skills will put bread on my table for at least another three years. And what “s after? Something else will come out, and I “ll make sure to be the first to learn it.

12. I “m not going to fall in love with any programming language, sorry, Flex. But I promise, we “ll have steady relations for a while.

Summary.

No we don “t need summary. Did I make myself clear?

Flash Player 9 on Linux and Adobe marketing

This morning I ‘ve read the blog of Adobe ‘s technical Flex evangelist James Ward, who had a chance to try pre-alpha Flash Player 9 on his Linux machine. James was pretty impressed and his Flex 2 applications work and look the same as in Windows or Mac as expected.

Flash Player 9 on Linux is big milestone for Adobe. Some of my Java peers are loosing one of their strongest arguments against accepting the fact that Flex 2 does your mind and body good. Knowing Adobe ‘s alpha-beta numbering scheme, I can guess that later this month at MAX conference they will announce Flash Player 9 Alpha on Linux, and one standing ovation and three months later, we ‘ll see shiny eye-candy applications running on Linux. The technical crowd (myself included) will write about a thousand of exciting blogs on the subject and will start casually using the product. But where? In the basements where many geeks spend their evenings? The end users won ‘t notice anything, because they are sitting by Wintel machines. But how about enterprises?

Adobe (credit to Macromedia engineers) was able to build a strong and vibrant community of people who enjoy working with Flex. Adobe ‘s technical evangelists deliver impressive presentations at conferences. So the-boat-shaking is working fine. But unless Adobe wants to share the fate of Ruby, which generates loud noise on the streets, but can ‘t pass security officers and sneak into corporate buidings, they should invest some serious dough into marketing. Java is huge not only because it ‘s a great programming language, but mainly because Sun Microsystems, IBM, and other big guys heavily invested into promoting Java.

In the past, Adobe was not a well known name in the enterprise IT departments. Yes, everyone uses Acrobat Reader, but this is pretty much it. It ‘s not an easy job to change the perception of being a designer ‘s vendor. Some serious investments into marketing of Flex 2 for enterprises is required. Need to jump a bit higher to get noticed from the Wall Street highrises. The sooner the better.

How to work for 50c per hour

If I offer you a job for fifty cents an hour, will you take it? This is what I ‘m doing now, and this is OK as long as the results of my work will not be stolen. I ‘m talking about writing a book. Each day I spend several hours after my regular hours working on a book. This is not an easy job, but it gives you satisfaction, industry recognition and the like. So I would not complain, but when I see the sites that offer you free bootleg version of the book it gets me upset. Basically these thieves are stealing more than modest royalties from the technical book authors.

My former co-author James McGovern has found this site offering his book for free. After complains, this Chinese thief removed this book ‘s file, but other bootleg books that are available there. This thief found a new business model: donate for using stolen goods. He writes: “If you find some useful stuff on this site, please kindly click on the PayPal button to donate some bucks to help me keep the site going on. MUCH APPRECIATED. ” But I doubt that anyone who likes using stolen materials would ever donate anything to this thief.

Several years ago one of my students from India has shown me a very thin (rice paper) and low quality printed version of a software book.

People steal even free stuff. Earlier this year a guy from India has stolen all my free Java lessons – he just did not bother mentioning my name. After a chain of shame-on-you emails, he removed my content.

In Russia it ‘s considered normal to share online books and commercial software.

People in these poor countries are often finding an excuse that their low wages stop them from buying books. I do not think this is the real reason. Many people have this mentality “Steal if you can “. It seems natural for them.

In developed countries people steal as well, i.e. kids are stealing (a.k.a. sharing) music, videos, but in general, the don ‘t-steal factor works much better here.

I do not know if there is a solution to this problem, do you? I ‘m not a religious person, but maybe people should spend more time in churches, synagouges, mosques or talking to buddhas?

I saw Lenin… in Seattle, Washington

Seeing this huge Lenin monument casually standing on one of the streets of Seattle, was a real surprise for me to say the least. People who are as old as Internet may not know who Lenin was, so this is especially for you: would you be surprised to see a 7-ton monument of Fidel Castro standing on the street of New York? Oh, you do not know what 7-ton is? Well, it ‘s heavy, trust me on this, or just take a look (this is Vladimir Lenin):

Here ‘s the story. This 16-ft statue was erected (if you do not know the word, think of Viagra) in Slovakia back in 1988, and in 1989 it was toppled and was just laying face down on the ground. An American entrepreneur Lewis Carpenter ran into it and like it a lot. I mean really really liked it, so he even mortgaged his house to buy and transport the statue to Seattle. This statue is a bit unusual, because it shows the leader or the world proletariat not just holding a book or surrounded by smiling pioneers (a communist-crafted boy/girl scout organization), but standing in flames and guns. Anyway, for 28 Grand Lewis brought it to the USA. Unfortunately he died in a car accident in 1994 leaving his wife with an unpaid mortgage and Lenin. Lenin was standing in a flea market for a while with a price tag of $150000, but now it ‘s on sale for $250000 (inflation, you know).

I hope one of these New Russians will be able to shell out a quarter of a mil and bring the Grandpa Lenin back to Russia, where he belongs. Lenin succeeded in building a society of equally poor people, and it should be pretty upsetting for him standing in a city of unequally rich American people.

If 90 years ago one of the poor people returning from Moscow would say “I saw Lenin ” , he ‘d be the only game in town. People would invite and treat him just to listen to some stories about this idol. So here I am, back from Seattle proudly announcing: “I SAW LENIN! “

Pace University does not know Pink Floyd

Pace University arranges meetings between the real world practitioners and computer science students. It ‘s my second talk at Pace, and this time I was talking about Java technical interviews.

I started with a story based on my article Another Brick in the Wall. To my disappointment, none of the students could answer which album was this song from. Is there something wrong with Pace, or I ‘m getting too old? Probably both. But this was the only negative moment of the evening.

After a short intro, I conducted a public demo-technical interview with a volunteer student from the audience. This brave guy gave me his resume, and I briefly went through it suggesting some improvements. A good resume is a key artifact in the job search, and its main goal is to get you an interview… After 15-minute interview I did a post-mortem analysis of mistakes of this “job applicant “. This was a successful and useful experiment. At the end, we ‘ve discussed with students some other Java interviewing techniques.

Pace professors have invited me to come back next Spring, which I ‘ll do with great pleasure.

ActionScript 3: Dynamic Classes

In Java, if you “ve created an object from a particular class, you can use only properties and methods that were defined in this class. For example, if the following class:

class Person {

String name;

}

you can only manipulate with the name property:

Person p = new Person();

p.name = “Joe rdquo;;

System.out.println(p.name);

ActionScript calls such classes sealed, but it also has different animals: dynamic classes, which allow you to programmatically add new properties and behavior to classes during the run-time. Just add the magic keyword dynamic to the class definition:

dynamic class Person {

var name:String;

}

Now let “s add dynamically two variables name and age and the function printme() to the object of type Person:

Person p= new Person();

p.name= rdquo;Joe rdquo;;

p.age=25;

p.printMe = function () {

trace (p.name, p.age);

}

p.printMe(); // Joe 25

You do not have complete freedom though: you can dynamically add only public properties and methods. Of course, nothing comes for free and sealed classes are a bit more efficient in terms of memory consumption, because they do not need to create a hash table to store the properties and methods that are unknown during compilation. Another obvious restriction is that dynamically added functions can “t access private members of the dynamic class. Read the blog Programming In Style or an Elevator Pitch to see how by just declaring standard Flex component dynamic, the your code becomes more simple and elegant.

In AS3, any function can be attached to a dynamically created property of a dynamic object, for example

function calcTax():Number { hellip;}

var myObject:SomeObject = new SomeObject();

myObject.tax=calcTax; //add the tax property and attach the function calcTax()

var myTax=myObject.tax();

The delete operator destroys the property of an object and makes it eligible for garbage collection:

delete calcTax();

myTax=myObject.tax() // generates an error

Some of the Flex classes were defined as dynamic, i.e. Object, Array, MovieClip, NetConnection, TextField, and others. At the time of this writing, subclasses of dynamic classes are not dynamic by default.

Because of this, you may run into an ugly run-time error: imagine a sealed class S that extends a dynamic class D. If you create an object as

D myObj = new S(), an attempt to add a propery to myObj will produce a runtime error because the variable myObj points at a sealed object.

Let “s do a quick test. Create a new project in FlexBuilder and select ActionScript project as its type. Enter AS_Only_Project as the project name. In a couple of seconds you “ll see the auto-generated code that looks as follows:

package {

import flash.display.Sprite;

public class AS_Only_Project extends Sprite

{

public function AS_Only_Project()

{

}

}

}

Next, create a new class called D and check odd the Dynamic checkbox in FlexBuilder pop-up. You “ll get this class.

package {

public dynamic class D

{

}

}

Now, instantiate and test the dynamic nature of the class D by adding the constructor

public function AS_Only_Project()

{

var myD:D=new D();

myD.favoriteBand= “Pink Floyd “;

trace( “Favorite Band= “+myD.favoriteBand);

}

Run this application in the debug mode, and sure enough it “ll print

Favorite Band=Pink Floyd

Create one more sealed class called S inherited from the dynamic D:

package {

public class S extends D

{

}

}

An attempt to add properties on the fly to the instance of the class S fails miserably as expected:

var myS:D = new S();

myS.favoriteSinger= “Alla Pugacheva “;

trace( “Favorite Singer= “+myS.favoriteSinger);

ReferenceError: Error #1056: Cannot create property favoriteSinger on S.

at AS_Only_Project$iinit()[C:\TheRIABook\eclipse\AS_Only_Project\AS_Only_Project.as:13]

If you “ll try to instantiate your sealed class as follows:

var myS:D = new S() as D;

I have two news for you: the good news is that it compiles, and the bad (and expected) news is that it generates exactly the same runtime error.

Most likely Adobe “s gonna hire a hitman and kill me after the following statement, but I “m going to say it anyway (at least you “ll now who to blame) hellip; May be I should not? hellip;Life is so good, and I “d like to witness the success of Apollo hellip;I “m sayyyiiiinng this:

If you need to add new functionality to one of the existing standard Flex components (buttons, comboboxes and the like), do not bother extending them and creating new classes. Just create one simple empty subclass with the keyword dynamic and instantiate and add new properties on the fly as needed, as was shown in the Smalltalk version in this article .

A sound of a silenced pistol shot. Curtain.

My upcoming Adobe Flex classes

After teaching Java for years, I ‘ve added yet another great tool to my menu: Adobe Flex 2. Beside being a developer who uses Flex 2 for real-world projects, I ‘m a co-author of the upcoming advanced book on developing RIA using Flex 2 and Java , which was not enough to become a certified Adobe Flex Instructor. I had to sit through a five day “train-the-trainer ” class taught by Adobe ‘s excellent instructor and book author (Matt Boles). After this class I had to pass the teaching exam by conducting a one-hour stand-up class using selected topics from Adobe ‘s training manuals. This was done and now I ‘m officially entitled to teach Flex 2 classes and use the courseware from Adobe.

Below is the list of my upcoming Adobe Flex 2 classes:

1. New York University , Manhattan.

This class consists of five evening sessions (Thursdays) over five weeks . This is a hands-on class, where I ‘ll cover all materials from the class Flex 2: Developing Rich Client Applications . This is a really great way to start your RIA-career in a slower pace.

2. Farata Systems , Manhattan, Dec 4-8. This course consists of five long days of intensive training: Flex 2: Developing Rich Client Applications and Flex 2: Data and Communications .

The students of these two classes will have preference in enrollment to yet another three days of the Advanced Flex training that will be taught by my colleage and co-author Dr. Victor Rasputnis in January 2007 (details will be announced shortly). This unique offering is not available from any other training provider.

I ‘d like to extend a special invitation to all of my former Java and PowerBuilder students to consider enrollment into one of the above classes if you ‘d like to be ahead of the crowd in your career planning.

To schedule private corporate onsite training anywhere in North America and Europe send an email at yfain at faratasystems dot com.

On sharing the source code of reusable components

I ‘ve seen a couple of times the posts stating something like this: “Since I developed the XYZ component for my client, I can ‘t share the code with you “. I ‘m talking about something like a TreeView control with check boxes by each node, or a thread pool optimized for the use with long running transactions.

IMO, we can share the code developed for our clients as long as it does not reveal client ‘s specific information. The very word “reusable ” means that I can use these components in more than one project. I do not think that the members of Gang of Four were laying on the beach and came out with design patterns. Most likely they were working on the real projects for the brick and mortar clients.

Of course, you may remind me that Sir Isaac Newton,was sitting under an apple tree observing an apple fall to the ground, and when he saw the apple fall, he began to think about a specific kind of motion mdash;gravity. I ‘m sure, the corporate lawyers have already discussed this situation a million times, and Mr. Newton would not have a chance to share his invention with the mankind had he worked for a Fortune 500 company.

Anyway, what ‘s your take on this?

Eating in Seattle

It ‘s my second day in Seattle – I ‘m here on Adobe Flex training business. After being in the classroom from 8 to 6, having a nice dinner helps. I was told that Seattle is famous for seafood, and there was a seafood place called Bonefish right by my hotel (belongs to the Outback chain). Boring place and boring food. Today, I decided not to take chances and asked for referrals at the hotel ‘s front desk, and they ‘ve suggested a place called Pasta Freska. On my own, I ‘d never even noticed this place, which is a small rancho squeezed inside a road fork. It ‘s very simple inside as well. The owner of the place started the dialog:

“Is there anything you do not eat? ”

“No ”

“How about a glass of wine? ”

“Thank you, but I prefer beer tonight ”

“I ‘ll bring you Peroni from Italy ”

“OK ”

Then I realized that this place does not have a menu. A nice smiling girl stopped by bringing something in a frying pan.

“What ‘s this? ”

“Some appetizer ”

I do not know what it was, but iIt was good. Then she brought me a green salad with a home made dressing. When I finished the salad, there was a pasta appetizer, I guess…Then, a tasty chicken cutlet with cashew nuts. When they brought me a seafood, I asked for another beer, and the owner simply said, “I ‘ll bring you a little bit darker beer this time ” – I did not resist. I enjoyed this game. He gave me a beer called India Pale from Oregon.

“Check, please ”

“You did not leave a little room for desert? ”

“No, thank you ”

Total damage: $31 + tips.

I have a reservation in a fancy restaurant for Friday night, but I ‘ll definitely will come back to Pasta Freska again this week. This is an experience.