Program in Flash or die!

I ran into an interesting blog written by a Flash programmer who feels that Adobe “s promotion of Flex puts him and other Flash programmers at a disadvantage.

He writes, “The times have changed and we all face the challenge to evolve. The fact that all these soon to be popular tools are build leveraging the Flash API is a tribute to the communities commitment and dedication to relentlessly extend the boundaries of the .swf format. Now we find ourselves competing with Java dudes…smart people, but no one knows the API better than us. We have worked with it from its infancy (/ syntax, tellTarget) to its current form. rdquo;

It “s clear that the author of this blog fell in love with Flash many years ago. But unfortunately software development is business, and big guys (Adobe in this case) do what they have to do to deliver competitive software. I happened to be one of the “Java dudes rdquo; who is using Flex now. First, the good news, Java dudes are not smarter than Flash dudes. Each programming environment has its own tricks of the trade, and based on my experience, GUI programming is often more challenging that writing efficient code for the back end. It requires a programmer to be a little bit of an artist, which is not an easily acquirable skill.

But professional programmers should not take any programming language too personal. You can “t love something that can “t love you back! Programming languages are tools and we learn them as needed. Can you fall in love with a Phillips screwdriver? While our blogger uses a professional language, another one has written a love letter to Flash. This anomaly is also known as fetishism .

Then, our blogger calls for the holly war, “My shout to the community is not to let the newcomers step on our turf. We hold the secrets of the flash API and are the rare ones familiar with its complexities, faults and vulnerabilities. Don ‘t give up, transition to AS3, learn MXML and help the community find ways to efficiently bridge the gap between Flex and Flash through your new IDE which should be Flex (SDK) rdquo;

It seems that the author would like to create a community that knows and passes from generation to generation undocumented secrets of Flash. This reminds me of a movie Rush Hour 3, where a secret list of thirteen Triad leaders was tattooed on the back of the head of a beautiful woman. Anyone is willing to shave his/her head and right there a couple of little known Flash APIs?

Unfortunately some Java, PowerBuilder, and Coldfusion developers are in the same state of mind. They want to protect their skills no matter what by creating all kinds of lobbies and publishing posts that would despise anyone who “betrayed rdquo; their clan in favor of another language.

Several years ago I ran into an ad in a Man Seeking Woman section. After listing the race and body parameters he requested that she should know Visual Basic. Apparently, otherwise they “d have nothing to talk about over the morning coffee.

Hey, let “s be friends. Program in Flex, Flash, or Java, or do not program at all. If you are good at one programming language it “s just a matter of time to be good at another one.

Remember, if the only tool you have is a hammer, everything looks like a nail.

How DHL can screw up your vacation

Usually we spend the third week of January skiing in Europe. Many years ago Martin Luther King had a dream, and now we have a day off on the third Monday in January. Take four more days off, and you get a nine-day vacation. Seven hour flight New York-Geneva, a short bus ride to France and you “ll find yourself in one of the beautiful ski villages . This year our friend, dedicated skier and a travel agent Dora (718) 875-5012 brought with her a group of forty six tourists.

Our ski vacation was going to start on Sunday, but some people arrived to Geneva on Saturday morning to spend an extra day in this nice city. Since seeing stores that sell watches, coo-coo clocks and Swiss knives one every block does not impress me anymore, our family and a small group of other people arrived to Geneva on Sunday. The bus picked us up in the airport and then went to Geneva to pick the rest of the tourists in the hotel.

Shortly after crossing the Swiss-French border (the bus just slowed down a little), Larry one of the skiers, came to the front of the bus saying that he left his passport in the safe deposit room in the hotel. Dora called the hotel, they opened the box and found the passport. Larry asked the hotel manager to mail the passports overnight to our French skiing resort located in 55 miles from Geneva.

Larry filled out all online forms on the DHL site, picked up “One day in transit rdquo; as a method of delivery and paid for it $150. This was on Sunday and DHL started the delivery process. The package went to Italy, the next day to Belgium, then it was delayed for a day for something called “clearance rdquo;. All these days Larry was tracking the package online, was making phone calls and sending emails. By Thursday, the package reached the city of Lyon in France. DHL “s representative explained that on Friday, the package will rich the town located in 50 miles from our resort, but since they do not deliver on the weekend, Larry would be better off to pick up the packed in that town on Friday (Larry “s plane is leaving on Sunday).

Today, Larry did not go skiing. In the morning, he rented a small car with a manual transmission in the closest Europe Rent a car (the only rental company available). The process took 50 minutes and the price was about $180+gas. He arrived to the DHL office at 12:10PM. Oops hellip;lunch time till 2PM. In Europe, lunchtime is a sacred as cows in India. At 2:10PM he “s got his passport, then a short 90 min drive back and another 50 min spent on the process of returning the car.

The bottom line. God bless America where overnight means exactly this, where there is no lunch breaks in customer facing businesses, where for $190 you can rent a luxury car and both the rental process and the return take 10 minutes each, where people “s mistakes are not punished as severely as in Europe.

The lesson learned. When Larry will leave his passport in this hotel ‘s room, he ‘ll just call the hotel manager to keep it in a safe place and will pick it up in a week on the way back. It ‘s easy to be smart afterward…

Ode to commute

If you live in a metropolitan area in the USA, your daily commute to and from work is seldom less than two hours. More likely, it “s anywhere from 2.5 to 4 hours. I live in New Jersey, and if I work for a client in New York City, I take a bus. If I work in New Jersey, I drive.

Commuting to Manhattan by bus

Lots of families moved from New York to New Jersey looking for a better quality of life, especially if they are raising kids. Many of them keep working in Manhattan, and if you “ll ask them, “How long does it take you to get to work? rdquo;, most likely they “ll lie to make their choice of place to live more attractive. For example, people in our town would say, “An hour rdquo;. Which is true at 2AM on a weekend when all roads are empty. The real estate agents shamelessly write that we are located “in a short 45-minute commute to the heart of New York city rdquo;, which is also true if your helicopter is waiting for you on your driveway with engines on and you have your own landing spot in the city. In the reality, if you leave home a seven in the morning, the chances are very high, that you “ll make it to the 9AM meeting.

New Jerseyans go to the city by train or by bus, and you can use this commuting time somewhat productively. People who live in the city take subway, which is an absolute waste of time. I take a coach bus, my laptop is with me all the time, Internet is on, and I do something useful while commuting ndash; blogging, reading the other people “s blogs, writing books and articles, watching movies, listening to the world radio stations over the Internet. I bought a laptop with just 13 inches monitor, so when the person in front of me reclines his seat, I can still work. When I was a rookie bus rider boarding a half full (or half empty?) bus, I “d select a row with two empty seats. Then, I quickly realized that this was a mistake, because as the bus picks more passengers, someone would definitely take a seat next to me, and the chances that it “d be a Playboy centerfold model were pretty slim. Most likely, it “ll be a two-hundred pound snoring guerilla in a dawn jacket. So I “ve learned my lesson, and now I pick my neighbor on the bus myself; even if I see a completely empty row, I do not take it. I take a seat by a young lady, or a skinny person of any age. A young lady is always a better choice, because she does not snore. On the other hand, she can immediately fall asleep on your shoulder which somewhat complicates the use of the laptop.

My dentist, Dr. Bella, lives in one of the boroughs of New York and has an office in Manhattan. She has golden hands and heart (212 889-8907). Dr. Bella works very hard commuting to Manhattan by bus paying her three hours a day to the Lord of Commute. Someone gave her an advice, rdquo;Move and live closer to your office and you “ll have extra couple of hours a day rdquo;. She said, “I have a couple of hours on the bus when I can rest and nobody bothers me, and you want to free these hours, so I can fill them with more work? Thanks, but no thanks rdquo;. Dr. Bella is a wise lady.

Commuting by car

Currently I have two clients in New Jersey. One is 53 miles away from my home and the other one “s offices are in short 60 miles. And I have to drive there. Driving is worse than riding a bus. My use of laptop is somewhat limited ndash; it “s hard to type while driving with a speed of 70 miles an hour. The laptop is still on, connected to the Internet, I created a small Web page with large buttons (so I can easily click on them while driving) that connect to various radio stations broadcasting over the Internet. I bought a little FM transmitter so the radio programs received by my laptop are being broadcasted through my car radio speakers. On the regular basis I “m listening to IT-related podcasts. If I “m stuck in traffic, I check my emails too. At some point, I was even recording carcasts ndash; this is what I call recording while driving. I was wearing a headset with a mike is connected to the laptop, and I was just dictating and recording right on my laptop ‘s hard disk. I “ve recorded and published (unedited) eight of them, but then I got bored. I “m still planning to learn French while commuting – I bought a CD but did not start yet.

Last week I met a colleague in the office. He was transferred to a different location and was complaining that now he spends five hours commuting. I “ve asked him, “What do you do while driving? rdquo; He said, “Nothing rdquo;. I suggested him to listen to the IT podcasts, Internet radio and told him about my FM transmitter. He said, “It “s a good idea, but I do not need a transmitter. My Hyundai has an input on the dashboard, and I can just plug in my MP3 player there rdquo;. I was really surprised, and this reminded me of another story.

Last year, my friend “s wife said, rdquo;Yakov, please talk to my husband. He wants to buy Hyundai. Talk him out of it rdquo;. OMG, Hyunday? I said to him, “Why you want to do this? Good programmers do not drive Hyundai! rdquo; He replied, “I did my research, and they offer the best value for the money rdquo;. I said, rdquo;It does not matter. Do not embarrass your wife. rdquo; He did not buy Hyuandai.

But this colleague of mine is also a very good programmer, and he does not give a damn about prestige and just drives Hyundai. While American car manufacturers were busy adding cup holders to their cars, only Hyundai designers were smart enough to add a little jack on the dashboard so people could plug in their audio devices right there! My hat off to Hyundai!

Telecommuting

IMO, in ten years, at least half of the IT workers will be working from homes. Sooner or later employers will realize that it “s just plain stupid requiring employees spend three hours in the car and $10-$15 a day for gas just to come to their cubicles. These “very useful rdquo; meetings can be attended by means of various video/audio conferencing tools that are mature and inexpensive. If you are a project manager reading this blog, please ask your team, “Who wants to work a day or two from home? rdquo; I “m sure this offer will be received really well. It does not matter if your corporate policy does not encourage working from home. Think out of the box, be a real leader and do something good for your people. Trust me, your business won “t suffer. Besides, you do not complain about not seeing the faces of your offshore team, why you local developers should not have the same privilege of not being in the office? Think about it and make a difference.

Morale

Here ” a relevant joke hellip;a little modified by myself.

God has invited religious leaders of all concessions. He said, “I do not like what “s going on Earth. Here and there Catholic (and priests!) are accused of child molestations. Orthodox church can “t defeat alcoholism. Jews do not observe Saturday. Muslims are blowing themselves up in the middle of shopping centers expecting that I “m going to give them 72 virgins for that. WTF? Go back and tell your people that if they won “t change for better, I “ll flood the Earth again, and do not expect Noah this time rdquo;.

A catholic priest returned from this meeting, gathered his people and said, rdquo;Guys, please stop molesting kids, otherwise in two months we “ll get flooded rdquo;.

The orthodox priest told his people, “Stop drinking, otherwise we all will die in two months rdquo;.

The Muslim leader said to his crowd, “Stop blowing yourself up, otherwise, we “ll get flooded and die in two months. Besides, I “ve got the insider “s info ndash; Allah is out of virgins rdquo;.

The Jewish Rabbi gathered his congregation and said, “Jews, we have only two months to learn how to live under the water rdquo;.

The bottom line: if you can avoid long commute, just accept it, make it as useful as possible and get a peace of mind as I did.

Flex Best practices. Sketch 1: An application with a single Event class

This is the first of the series of articles that Flex architects from Farata Systems will be posting over the next several months. We “ll introduce you to our own class library that goes by a working name theriabook. Over the last couple of years we “ve been successfully using various coding techniques and custom components that turned the application development in Flex into a RAD project.

I “ll start with some history and definitions. While working on the book “RIA with Flex and Java rdquo;, we “ve been building a library of reusable components for the book samples. Since the book writing was our moonlight activity, we “ve had a chance to try all these components at the battlefield ndash; during our consulting gigs with various clients. Unfortunately, last week we “ve had to politely reject the offer of our publisher, Sys-Con Media for writing the second edition of that book. We just do not have time. So if you are thinking of purchasing a copy, do it sooner than later – it “ll be gone soon.

There are three ways of writing software:

1. Just write the code from scratch

2. Pick a framework and write the code by the rules dictated by this framework

3. Use selected components from one or more class libraries

To see the difference between a framework and a class library, visualize a construction site of new housing development. In one home site, you see a frame of the future house, rooms are laid out, and electrical wire are hanging everywhere . The site next to it just has a pile of construction materials ndash; Anderson windows, 2X4th, et al. Of course, the latter gives you a lot more freedom as to how your future house will look like hellip;as long as you know how to construct it.

We like freedom, and will be presenting not only our “Anderson windows rdquo;, but also instructions for using them during construction of your application. Best practices, as we currently see them. Your input is greatly appreciated and if you have your own construction materials or tricks of the trade, please add them to our pile.

All objects from our theriabook library will be available for free as an open source software governed by the MIT license ndash; the same as Flex framework.

Without further ado, let “s go to our first best-practice.

An Application With a Single Event Class

Flex is all about event-driven development. Create loosely coupled objects and let them send events to each other. You can read about this in the following blog

In a nutshell, you can create new events for every occasion you need. If an event does not need to carry any additional data, just extend flash.events.Event, and define the meta-tag to help Flex Builder listing this event in its type-ahead prompts and dispatch it when appropriate. If your new event needs to carry some data, create an ActionScript class, define a variable in your subclass to store your data, and override the method clone();

If we take a mid-size Web site with 10 views, where each view has two components that can send/receive two events, you can quickly rich forty or more custom Event-based classes that look pretty much the same. To ensure that the situation does not go out of control, some of the Flex frameworks force you to register upfront each event in a central location.

We say, “No need to do it. You can get away with one event rdquo;. So a sample application below has only one defined event class that can fit multiple purposes without the need to introduce tight coupling between your application components.

To illustrate the concept, I “ve created a simple application that looks as follows:

This application consists of two modules (GreenModule and RedModule) that are loaded in the same area of the main application on the click of the appropriate Load button. It also has one universal event class called ExEvent. If you click on the Send buttons, an instance of this event is created and you can put there an instance of Object, a DTO, a couple of string variables, nothing, or anything else you like. In this example I “m using a DTO class called GirlfriedDTO.as. There is no mapping between the event you send and the modules. For example, if you send a Green event to the Red module, nothing happens since the Red module is not listening to the Green event.

I “ve been using modules in this application not because I endorse them, but rather because they give me a chance to quickly illustrate a concept of run-time loading and lose coupling between the objects and events. Victor Rasputnis, my colleague at Farata Systems has been experimenting with modules and next month will publish an article describing his findings.

A completed application and its source code is deployed at this URL. Its Flex Builder “s project has a folder modules that contains two modules ndash; red and green. The red one is listening for the arrival of the girlfriend “s first and last name packaged in our single event class as two separate strings:

lt;?xml version= “1.0 ” encoding= “utf-8 “? gt;

lt;mx:Module xmlns:mx= “http://www.adobe.com/2006/mxml ” layout= “absolute ”

width= “100% ” height= “100% ” creationComplete= “onCreationComplete(event) ” gt;

lt;mx:TextArea id= “display ” backgroundColor= “#FF4949 ” width= “100% ” height= “100% ” fontSize= “28 “/ gt;

lt;mx:Script gt;

lt;![CDATA[

private function onCreationComplete(evt:Event):void{

this.addEventListener( “RedGirlfriend “, onRedGirlfriend);

}

private function onRedGirlfriend(evt:ExEvent):void{

display.text= “My girlfriend is “+ evt.fName+ ” ” + evt.lName ;

}

]] gt;

lt;/mx:Script gt;

lt;/mx:Module gt;

The green module expects girlfriend “s name in a form of GirlfriendDTO:

lt;?xml version= “1.0 ” encoding= “utf-8 “? gt;

lt;mx:Module xmlns:mx= “http://www.adobe.com/2006/mxml ” layout= “absolute ” width= “100% ” height= “100% ”

creationComplete= “onCreationComplete(event) ” gt;

lt;mx:TextArea id= “display ” backgroundColor= “#9CE29C ” width= “100% ” height= “100% ” color= “#070707 ” fontSize= “28 “/ gt;

lt;mx:Script gt;

lt;![CDATA[

import dto.GirlfriendDTO;

private function onCreationComplete(evt:Event):void{

this.addEventListener( “GreenGirlfriend “, onGreenGirlfriend);

}

private function onGreenGirlfriend(evt:ExEvent):void{

var myGirlfriend:GirlfriendDTO=evt[ “girlfriend “];

display.text= “My girlfriend is “+ myGirlfriend.fName+ ” ” +

myGirlfriend.lName ;

}

]] gt;

lt;/mx:Script gt;

lt;/mx:Module gt;

The GirlfriendDTO is located in the folder dto and is pretty straightforward too:

package dto

/**

* This is a sample data transfer object (a.k.a. value object)

*/

{

public class GirlfriendDTO

{

public var fName:String; // First name

public var lName:String; // Last name

}

}

Now let “s talk about our single but universal event class. It “s based on the DynamicEvent class, which allows you to add any properties to the event object on the fly. Surprisingly, Flex documentation discourages you from using this class. Here “s what it reads:

This subclass of Event is dynamic, meaning that you can set arbitrary event properties on its instances at runtime. By contrast, Event and its other subclasses are non-dynamic, meaning that you can only set properties that are declared in those classes. When prototyping an application, using a DynamicEvent can be easier because you don ‘t have to write an Event subclass to declare the properties in advance. However, you should eventually eliminate your DynamicEvents and write Event subclasses because these are faster and safer. A DynamicEvent is so flexible that the compiler can ‘t help you catch your error when you set the wrong property or assign it a value of an incorrect type.

Let me respectfully disagree with this recommendation and suggest you to use the dynamic nature of this event not only for prototyping, but also for development and deployment of your applications. When GUI components send event to each other, the difference in the processing of your dynamic vs. static event instance is negligible. It “s not clear how safer the static event are. I do not think so.

When you design an event-based interaction between components of your applications, both the sending and receiving parties must know in which format the data are being delivered by an event. And we utilize this knowledge even in case of the dynamic events. We can use either a well defined GirlfriendDTO:

var myDTO:GirlfriendDTO=new GirlfriendDTO();

myDTO.fName= “Mary “;

myDTO.lName= “Poppins “;

var greenEvent:ExEvent=new ExEvent( “GreenGirlfriend “);

greenEvent.girlfriend=myDTO;

someObject.dispatchEvent(greenEvent);

or just add two string variables:

var redEvent:ExEvent=new ExEvent( “RedGirlfriend “);

redEvent.fName= “Mary “;

redEvent.lName= “Poppins “;

someObject.dispatchEvent(redEvent);

In this sample I use an ExEvent, which is a subclass of the DynamicEvent ndash; it just has a little enhancement that eliminates manual programming of the property Event.preventDefault:

package

{

import mx.events.DynamicEvent;

public dynamic class ExEvent extends DynamicEvent

{

private var m_preventDefault:Boolean;

public function ExEvent(type:String, bubbles:Boolean = false,

cancelable:Boolean = false) {

super(type, bubbles, cancelable);

m_preventDefault = false;

}

// It ‘s an enhancement: DynamicEvent class does not

// automatically process preventDefault in cloned events

public override function preventDefault():void {

super.preventDefault();

m_preventDefault = true;

}

public override function isDefaultPrevented():Boolean {

return m_preventDefault;

}

}

}

Now the code of the test application loads modules, and then the user can send any event to whatever module is loaded at the moment. Of course, if the currently loaded module does not have a listener for the event you “re sending, tough luck. Do not expect miracles ndash; nothing will happen. But the good news is that it won “t break the application either:

lt;?xml version= “1.0 ” encoding= “utf-8 “? gt;

lt;mx:Application xmlns:mx= “http://www.adobe.com/2006/mxml ” layout= “vertical ” viewSourceURL= “srcview/index.html ” gt;

lt;mx:HBox gt;

lt;mx:Button label= “Load the Green Module ” click= “loadMyModule( ‘modules/GreenModule.swf ‘) “/ gt;

lt;mx:Button label= “Load the Red module ” click= “loadMyModule( ‘modules/RedModule.swf ‘) “/ gt;

lt;mx:Button label= “Send Green Event with Object ” click= “sendGreen() “/ gt;

lt;mx:Button label= “Send Red Event Event with two strings ” click= “sendRed() “/ gt;

lt;/mx:HBox gt;

lt;mx:Panel width= “100% ” height= “100% ” title= “A module placeholder ” layout= “absolute ” gt;

lt;mx:ModuleLoader id= “theModulePlaceholder ” width= “100% ” height= “100% “/ gt;

lt;/mx:Panel gt;

lt;mx:Script gt;

lt;![CDATA[

import dto.GirlfriendDTO;

//Load the module specified in the moduleURL

private function loadMyModule(moduleURL:String):void{

theModulePlaceholder.url=moduleURL;

theModulePlaceholder.loadModule();

}

// Sending generic ExEvent adding an object that contains

// the name of the girlfriend

private function sendGreen():void{

// Strongly typed DTO – better performance and readability,

// but its structure has to be known for both parties –

// the main application and the module

var myDTO:GirlfriendDTO=new GirlfriendDTO();

myDTO.fName= “Mary “;

myDTO.lName= “Poppins “;

if (theModulePlaceholder.child !=null){

var greenEvent:ExEvent=new

ExEvent( “GreenGirlfriend “);

greenEvent.girlfriend=myDTO;

theModulePlaceholder.child.dispatchEvent(greenEvent);

}

}

// Sending a generic ExEvent that holds the name of the girlfriend

// as two separate variables

private function sendRed():void{

var redEvent:ExEvent=new ExEvent( “RedGirlfriend “);

redEvent.fName= “Angelina “;

redEvent.lName= “YouKnowWho “;

if (theModulePlaceholder.child !=null){

theModulePlaceholder.child.dispatchEvent(redEvent);

}

}

]] gt;

lt;/mx:Script gt;

lt;/mx:Application gt;

The function sendGreen() sends an instance of our ExEvent event with DTO, while the sendRed() just adds two properties fName and lName to the instance of the ExEvent.

Instead of using a well defined DTO, I could “ve used a weakly typed data transfer object:

var myDTO:Object={fname: “Mary “,lname: “Poppins “};

But this would result in poor readability of the code and a bit slower performance. On the positive side, there would be no need to explicitly define and share the class structure of the dto between the app and the module. I “d do something like this during the prototyping stage, but not in a real code.

Let “s recap. What did we gain? No need to create lots of tedious coding defining dozens of similar event classes. What did we lose? Since we did not use the metatag Event declaring the names of the events those never declared event classes, Flex Builder won “t be able to help us with the name of the event in its type-ahead help. No biggie.

In the unlikely case if there is a view in your application that can “t afford to lose a couple of milliseconds caused by using dynamic event, use static but in that view only. But with a single dynamic event the code base of your project will become smaller, and more readable.

American sketches: ER and neighbours

Sunday evening, my younger son comes to the kitchen complaining about the pain in the right part of his belly.We suspected appendicitis, but decided not to spend a night in the ER. Our next door neighbor is a physician who works in the ER. We did not even think of knocking at his door. America practices protective medicine, which means that a doctor ‘s main goal is not to get a law suit. We knew that he would not give us any advices other than going to ER.

Today, my wife went to our pediatrician, she also suspected appendicitis and told my wife to take my son to ER immediately. She did. To their pleasant surprise, they saw our neighbor in the ER. He gave her a warmest hug and a kiss (they did not talk to each other foe several years – this is how the neighbor live here. She was really happy to have an insider in the ER. He said to my son, “Do not worry, it ‘ll be fine “.

My wife recovered after the hug, and asked the physician, if he might have an idea what can be the diagnosis. He answered, “Do not worry, the nurse will tell you everything. ”

He was afraid to say anything even in ER! Hug and kiss do not mean anything, but he wants to stay out of troubled for giving the wrong advice. That ‘s why we did not even think to ask a neighbor physician for help in the first place. America 😦

Staffing a team for your Flex project

At the end of 2006 I wrote in a blog that Flex programmers should sit tight, improve their skills and wait till 2008 ndash; the year of their fame. The year of 2008 is here, and Flex people are in big demand. Two years ago, Flex community was more of a ghetto where most of the Flex programmers knew each other, but situation is different now. The number of Flex programmers is increasing, and this population evolves similarly to what I “ve seen in the Java camp in the past.

The main concern of any project manager is if there are enough people in the pool of Flex developers to staff the project. Yes, there is a pool of Flex developers, but let “s look at the creature called “Flex Developer rdquo; under the microscope.

Presently, I work for two clients from different industries; both projects are redesigns of existing Java applications. One project has a small number of Flex screens but very serious requirements for the communication layer. The other project has lots and lots of screens with LCDS on the back. Both projects require three types of Flex personnel:

1. Flex GUI developers

2. Flex component developers

3. Flex architects

The first group is people who can create the view portion of the application. This is the easiest group to get into if you already have some programming language behind your belt. The rumors about high consulting rates plus work of educators and technical evangelists create an impression that working with Flex is easy ndash; just drag and drop components on the screen, align them nicely and write the functions to process button clicks or row selections in the data grid. Sort of a Visual Basic of the Web. These skills are easy to obtain, and you can expect a crowd of people there, but do not expect high pay rates in this segment. If something is easy to learn many people can master it, and savvy project managers either outsource this job to a third-part vendors or send their own developers to a one-week Flex training class.

GUI developers interact with Web Designers that come up with the look and feel of the screens, which can be presented as a wireframes created in Photoshop, some third-party tool or even in Flex itself. But even in the latter case, GUI developers should not start implementing screens until approved by a Flex component developer or an architect.

While this is a right way to start Flex career, you definitely should consider moving to the second group and become a Flex component developer. This title is awarded to people who know everything that GUI developers know plus object-oriented and event-driven programming. Knowledge of design patterns helps, but be careful here. Especially it applies to people coming from the Java world. Do not abuse MVC. Think out of the box. A screen created by a Web designer has to be scrutinized and redesigned into a set of components that communicate with each other. Applying the Mediator pattern to the initial wireframe is a good start as I “ve described in this blog .

Also, keep in mind that even though the syntax of ActionScript 3 looks very similar to Java, it has provisions for dynamic programming and you might not need to create tons of well defined objects as in Java.

The third group of people knows everything the first two groups plus they can see a big picture. They know how to build the entire application, how to communicate with the mid tier, how to structure your project, and how to make communication between reusable components, views and the persistence layer the most efficient. Flex architect are people who “d never suggest using a framework for creation a simple Video player as done in this blog. You do not gain these skills after a week of training, but you build them on top of your prior experience in other programming environments and by constant studying.

Not every Flex developer can be profiled as a member of one of these three groups. In smaller teams, one person may wear two hats: a component developer and an architect. If your team has decided to use one of the frameworks on top of Flex framework, you may wind up with a new type of team members that can be called framework coders. In this case it is assumed that this XYZ framework provides a structure that will take care of inter-communication between components, and coders just need to put their model, view or controller objects into the right directories, buy popcorn, press the button “Play rdquo; and watch the movie. This may or may not work as expected, but you may find out about it later in the game. If you are not lucky and the film got stuck in the projector and caught fire well into the movie, get ready to ask for an extra budget for a new project called “Removal of the XYZ framework rdquo;, which reminds me of a good old joke.

A poor man comes to the rabbi complaining that his family has only one small room, many kids, and almost no money. The rabbi says, “Take all your money, buy a goat, and keep the goat in your room. Come back in a month. ”

“But, rabbi, we don ‘t have enough space even for us, ” the man said

“Just do what I say, ” the rabbi replied.

A month later the man comes back complaining that the goat smells and breaks everything.

“Sell the goat and come back in a month, ” the rabbi tells him.

A month later the man comes back to the rabbi with flowers.

“Thank you, rabbi! We ‘re so happy the goat is out, now we have more room and some money from selling the goat! ”

If you are considering adding Flex to your set of skills, it “s still early in the game and you can join the fast growing Flex community. Decide which group of the Flex developers looks most appealing to you. Set a goal and go for it. Be what you can be.

Do not turn Java into C++

When I run into yet another posting about adding yet another cute little element to Java syntax, it makes me sad and angry. It seems that people are converting Java into a some kind of a science project.

Someone asks, “Kids, what new features you ‘d like us to add to Java language? ”

And the chorus responds, “We want this, we want that…And we want it now! ”

“OK kids, we ‘ll give you this and we ‘ll give you that. We can ‘t give it to you now cause we have a process. We ‘ll run experiments on humans, and if not too many software developers will stop using Java because of these new features, we ‘ll stick them into the language spec. ”

We had a nice language, then it became a platform, then for some people it became a religion. Some time ago I was trying to participate in various Java forums. But then I realized that if you are not 100% for Java, some of them become dangerous places to be. If you even mention any other language that people are using behind the fence (should I say behind the iron curtain?) you become an enemy.

And the closures discussion is a pinnacle of what can be done to screw and bury Java. Closures are discussed by the best minds in the community, but when I look at the proposed syntax, I get an impression that these best minds are flying so high, that they do not have time to see how these closures are implemented in other languages. While the trend in other languages is to hide the complexity by engaging under-the-hood-code-generators, Java closures proposals are forcing a programmer to do all the calligraphy.

JavaFX is an a little-to-late response from Sun to the rapidly growing community of the languages, tools and techniques for development of the rich Internet applications. Fine, let ‘s give JavaFX some time, it ‘s still too young. But what can you expect from a scripting language built on top of Swing libraries? This is already outdated…even before its own release. I hope to see some real competitive sample applications showing the power of JavaFX rather than declarations that it ‘s a Flash or Silverlight killer. This is not even funny.

JVM is very robust. Why not concentrating major efforts on Consumer JRE, Java Kernel, creating new languages that can run on JVM?

Java as the language is pretty stable in the server-side enterprise applications. A typical IT shop of a large firm in the USA is either Java or .Net.

You may argue that J2EE is too heavy and will be replaced with “lighter frameworks “, but in the end, it ‘s still Java. You may not like the fact that Google ‘s Android is not using Java as the doctor ordered, but hey, it ‘s still Java.

Even without any new additions Java is not going anywhere and we can safely retire developing applications in this great language. The Java bookshelves are already shrinking in size, which is clear indication that less people are interested in this language. Please leave the Java syntax alone. KISS.

Answering James Goslings Flash Player Comments

Redmond Developer News has published an interview with Dr. James Gosling, creator of the Java language where among other things, he talks about JavaFX and competing technologies. And he made a comment I can “t agree with. Here “s the quote from that interview:

“As organizations think about building rich Internet applications or rich client applications, when should developers look at JavaFX over competing technologies?

If you look at something like Flash, when you get to the much more advanced stuff — richer interfaces, more complex network protocols, more complex APIs — it really falls short. We ‘ve had a platform for years that can build rich Internet applications that are extremely sophisticated. rdquo;

Before even going to technical details explaining why this statement is wrong, let me tell you that if someone would ask me to name a dozen of the most respectful people in the industry, James Gosling would be one of them. Because of him, I live in a nice house and drive a nice car ndash; I “ve been doing Java for the last ten years. If James would not invent Java, I “d be probably still working with PowerBuilder writing that it “s the best thing since sliced bread.

But let “s go to the essence of the accusations. Dr. Gosling does not attack the presentation and delivery abilities of Flash Player because Flash Player is today “s leading delivery mechanism for rich Internet applications. He addresses network protocols, something that may not be as easy to argue. So let “s talk protocols.

In 2007, my colleague and I were invited by a financial company (a Java shop) to assess if they could create an Internet version of their trading application using Flex. They did not have any doubts the GUI part should be done in Flex and delivered to their customers by Flash Player. Using AJAX for such an application would be crazy.

Sun “s long history of ignoring Java as platform for delivering Internet applications ruled Java applets out. A dancing Duke made his short appearance in 1995 and was forgotten by Sun for the next 10 years. Can you imagine Amazon or Google using Java as a front end for their applications? It “d be insane ndash; they “d lose a half of their customers trying to persuade them to use Java applets – each of them had different version of JRE and installing the right one required a college degree in computers. I hope this situation will change with the introduction of Consumer JRE later this year, but we are not there yet.

Anyway, this financial company was not sure if the communication protocols offered by Flex were robust enough to provide reliable and guaranteed message delivery and could be extended to accommodate specific needs of this application, such as adding the application-specific quality of service (QoS) information right to the packages sent over the network from the Flash client to Java server-side application. They wanted some other things too, such as message throttling in case of network congestion and more.

Flex offers a server-side piece called LiveCycle Data Services ES, which comes with a couple of fast communication protocols: AMF ndash; a binary protocol that makes calls over HTTP from client to server (polling) and RTMP ndash; real time messaging protocol that supports real time push from the server to Flash client. By the way, AMF goes open source in a month or so (see BlazeDS). Java offers RMI protocol for RPC and JMS for messaging. RTMP is easy to integrate with other messaging systems via JMS. Security is similar to Java applets (sandbox) and you can use RTMPS instead of RTMP.

Under the hood, AMF and RTMP protocols implement object serialization, so an instance of a Java object gets serialized on one end and is recreated as an instance of the ActionScript object on the client inside Flash Player, which is nothing else but a VM. On the way back, an ActionScript object is serialized on the client and gets recreated in the server “s JVM as a Java object.

One of the most important features of the Flex framework is that it “s extendable. The server side of implementation of these protocols is written in Java, and the client side in ActionScript 3. To make the story short, we were able to extend the communication channels, end points, message consumers and producers to enrich RTMP protocols to the clients specification. Now the messages about trading orders and executions travel happily between the Flash client and Java server. Security is similar to Java applets (sandbox) and you can use RTMPS instead of RTMP.

This project was an example of a nice marriage between Flex and Java in a Wall Street application. If Flex has weak spots, it “s slow compiler and a mediocre (by Java standards) Eclipse-based IDE . Since Flex is open sourced now, I hope that some third-party company will create a better IDE and improve the compiler.

But as of now, I “m pretty happy with using both Java and Flex technologies, and the good part is that it “s not an either-or situation ndash; just use the right tools for the job. There is no need to lobby for any particular language. As to JavaFX, I wish it to start competing with Flex and Silverlight as soon as possible. The more the merrier.

Some time ago I said to my kids, “Even if, God forbid, you “ll commit a crime, Mom and I will still love you and will try to protect you to the very end. You are our kids and we love you regardless of your achievements and personal qualities rdquo;. It seems that James Gosling has the same principles and protects his baby no matter what. I respect this but have my reservations.

James Gosling ‘s fan,

Yakov Fain

Time Magazines 50 best Web sites

Time magazine has published their version of 50 best Web sites of 2007 . Check it out. You may or may not agree with their ranking, but I ‘m sure you ‘ll find some interesting sites there that you did not know about. All these sites are Web2.0-ish, which by my definition are not the sites that were built using any particular technology, but rather the sites that give more control to the end user. So while some people say that Web 3.0 is about semantic Web, I believe that Web 3.0 sites will just give the end user more control than Web 2.0 ones.

But since developing rich Internet applications is my main professional activity, I could not stop myself from looking what ‘s under the hood at the Time ‘s Web site.

It ‘s good to see that they are gradually introducing Adobe Flex to their Web site. While most of the Web site is done using DHTML, the widget that shows “Top 5 Best Web Sites ” is done in Adobe Flex. Just right-click on that area and you ‘ll see that it was delivered by Flash Player. To be more specific, most likely it ‘s a custom component that consists from a VBox container (a box with vertical layout) that in turn has an HBox and a DataGrid. The HBox holds the Label that reads Top 5 Best Web Sites ” and two buttons – one is a button with an image Refresh Data and the other one is a button with a custom skin that looks like a circle(?). As you move your mouse over that button, you ‘ll see a tooltip that shows you a hint that the DataGrid below is sortable – just click on the column ‘s header. If Time developers read this blog, I ‘d appreciate if someone would confirm that I ‘ve guessed your Flex components selection correctly.

I applaud Time for using Flex. Just think about it, this little widget that displays the rating can be coded in no time – one hour for coding and testing and one hour for the skin creation, which can be done in parallel by a Web designer in Photoshop. The speed of development is crucial for any multimedia mega site such as Time magazine.

Of course, since they are just starting, there are some usability issues, for example if you sort the ratings table by any other than Rate column, the text of the Label above should change from “Top 5 Best Web Sites ” to something else based on your sort criteria.

Another usability issue – there is a column Total Votes, but it ‘s not clear how the user can vote. I ‘d use a custom item renderer in the Total Votes column to turn the number of votes into a clickable link that would bring the user to the voting page. In Flex, this would take another 5 lines of code.

But these are the little things that will be ironed out in the future. Good job, Time Magazine! Go Flex!

Update. One of the readers (thank you, Zohar) gave me a reference to a Web site created by James Ward to check if a site was created in Flex

http://www.jamesward.org/is_it_flex/

If you try this URLhttp://www.time.com/time/flash/time50BestWebsites/top5/top5_websites.swf you ‘ll see that the site was not created in Flex. Oh, well, at least it ‘s ActionScript 🙂 Time, go Flex!

Do we need third-party Flex frameworks?

This started as a Skype chat room conversation between my colleague Anatole Tartakovsky and myself, and I thought that it would be a good idea to invite more Flex developers to this discussion.

Having said this, I “d like to make it clear that over my career, I “ve been developing frameworks and truly respect people who are capable of creating frameworks, and Anatole has huge experience in this area as well. Here we “re just questioning the need to create frameworks not for a general-purpose language like Java, but for a domain-specific framework like Flex.

This is our dialog with minor editing. Your input and feedback are greatly appreciated.

Yakov: Why do people design Flex frameworks as opposed to reusable components? One of the framework is called Cairngorm, the other one is called PureMVC. I “m sure there is more. It seems to me that such frameworks are unnecessary overhead over well-designed Flex frameworks. Are there any benefits here? Why bother creating all these singleton-based bottlenecks?

Anatole: First of all, PureMVC seems to be more of an ActionScript Framework. It is not specifically a Flex framework and concentrates on the task of creating a generic framework for low-level AS objects. Flex comes with “prebuilt suggestions rdquo; of how a model/view controller might work – and it offers lots of hooks throughout the data and UI classes that help implement MVC.

PureMVC is also “server-agnostic “. Flex made the Java implementation of a distributed Model that can provide dynamics to the distributed Web applications very efficient. PureMVC is more about making apps in a more traditional way.

Cairngorm was started as “Micro ndash; Architecture rdquo; ndash; a set of patterns that allowed the solving of certain problems in the application design ndash; like Model Locator or Commands ndash; and certain applications. It never appealed to me as it had a number of assumptions that required more coding. At best you would use one or two pattern implementations from Cairngorm, but it “s much easier to rip out the part you need and adjust it to your liking.

Yakov: I can appreciate the fact that design patterns are useful in general, because they may help developers deal with repeating patterns in software constructions such as Singleton, Mediator, Model-View-Controller and the like. But when I look at some of the third-party frameworks built on top of Flex, I keep asking myself the same question, “Why build a framework on top of a framework? Are there any benefits to introducing a middleman between an application ‘s views and an already existing Flex framework?

Anatole. It depends on the application you are building. Frameworks provide higher level of automation and abstraction for specific tasks and with various coding and performance costs. Fo example, Flex framework has Data Management Services for distributed Web applications. However, this model has limited applicability for simple Web applications working with HTTP forms-based backend API. You “d need a symmetrical MVC API on the client side. You can also have a client-side only text editor application, for example, that is completely “out of scope rdquo; for Flex framework but would benefit from implementing a Command pattern. The real question is to identify the functionality you need, and then to see how it is implemented in the appropriate framework

Yakov. I looked at the Cairngorm “s design, and having hard times figuring out why would I need something like this? Ok, you may say that it helps to organize your project better. What else? Without any disrespect to creators of Cairngorm, I can ‘t find a justification to recommending it to my clients. One of them has invited me to lead an ongoing Flex project, which is being developed by a large team of developers. The project uses Cairngorm, and at the same time it consists of a number of modules. After reviewing the project, I ‘ve recommended to stop using Cairngorm. Without going into details, these are some of my concerns in this case:

The client wants to use modules, which are can be loadable/unloadable. But since you are forced to use Cairngorm ‘s singleton model locator, it ‘ll keep the hard references to the modules (event listeners), which won ‘t allow you unloading modules. So, on top of Flex modules ‘ memory leaking (yes, they leak), we ‘d introduce another memory issue.

Anatole. In many cases, a detailed look at the implementation will either get you on board or will remove the framework as not applicable implementation. In later releases of Cairngorm you can have weak references – so it works – at least theoretically. However, with modules there are quite a few places when unloading will become impossible due to legitimate code generated by framework. In general, if you are going with modules, you need multi-layered framework and intelligent registration services that are written specifically for the task.

Yakov. As far as I know, the use of Cairngorm was never approved by Adobe Flex team, but I might be wrong here. Flex framework is built on a nice distributed event-driven architecture, but Cairngorm is forcing your events to go through another singleton – event dispatcher. Why is that? Why every view has to register event listener in a central place? Now developers on a large project have to acquire additional skills in proper usage of this framework.

Anatole. The reason for use of global event listeners registration are derived from the size / type of applications the framework developers worked with. It “simplifies ” the project management by providing structure and separating developers responsible for model, view and controller into separate entities. All these singletons and managers are a way to establish a non-UI but business communication between parts.

Yakov. Do we really need global areas? Why not doing it locally when needed?

Anatole. First, you need to look at the events. In most cases, these are not UI or input events but rather some application/state changes that need processing. The model is global, and the application events are defined on the global level.

I think most of the seasoned developers with UI background are uncomfortable with this approach. You might want to consider Joe Berkovitz MVCS approach as a middle ground between Cairngorm and our component-based approach that might work better for medium to large size teams that would have no access to code generators and data driven/factories-based architecture.

I recall two framework-related sessions at MAX “07, where approximately the same number of people were asked the question: how many of you have looked at Cairngorm? 70% -80% raised their hands during the Flex frameworks BOF session and 90% on the Best Practices session. During the Flex framework session people were asked a second question, ” How many of you would use or actively oppose Caingorm? ” This time they “ve got a 50/50 split.

Yakov. I hope to be able to attend MAX 2008. So all these people came to the Best Practices session to get reassured that they are doing the right thing? But I “d really want to see some concrete examples where using these frameworks would bring technical benefits. I want to stress, I ‘m not talking about self-contained components that would automate some tedious job but a framework on top of Flex Framework.

Anatole. I think the main benefit of any pattern library will be based on its applicability to your application. There are quite a few applications ndash; including infamous “shopping cart rdquo; ones ndash; that can be coded quite efficiently with any of these frameworks. On the other hand, the extra setup code provided for “flexibility rdquo; is ironically the least flexible part of it.

As far as benefit ratio between an architectural framework and smart components, I think you might want to try a little test. Ask any developer if she wants an architectural framework that still would require her to implement a DataGrid componment (she would be allowed to use Grid component or some other low level controls as a superclass). On the other hand, offer her a DataGrid component without any framework. I think this developer would recognize the importance of smart objects and go with a DataGrid. Take it a level deeper and you will see an “extra rdquo; code in a DataGrid , and we “ve successfully have overridden it in our own DataForm, SuperGrid and controls.

Yakov. Do not forget though, that we are enterprise developers and are mostly concerned with a boring thingy called data processing. There are legions of Flex developers who do not care about the DataGrid. They are into creation of cool visual components. But these guys do not need any frameworks either.

Here ‘s another strong statement from the PureMVC framework, “The PureMVC framework has a very narrow goal. That is to help you separate your application ‘s coding concerns into three discrete tiers; Model View Controller “.

But isn ‘t this goal already achieved in Flex Framework? Wouldn ‘t a simple separating views, controllers and models into different folders of your project suffice? In many cases the role of Controller in Flex is kind of blended into model itself (bindable data collections can emit and listen to events caused by some data changes). In some cases, if your application ‘s views have reusable business logic (i.e. validation or connection to specific back end data feed) you may create separate controller classes that may be shared by more than one view. But this should be done on the case-by-case basis, and not as a must for the entire application.

Here ‘s another statement from a well-written PureMVC documentation: “Making separation of Model, View and Controller interests eliminates the most harmful responsibility misplacement issues that hamper scalability and maintainability “. My English is not good enough to understand this phrase in its entirety, so can you play the PureMVC advocate and suggest, how PureMVC would improve Flex scalability and maintainability?

Anatole. Well, there is an old saying that life is a play, written by God, and directed by Devil. By making the process more formal you can build a lot smaller chunks, communicating and specific way, and in your mind the more formal process will yield better maintainability. On the other hand, it will create more parts to maintain and less flexibility to do so.

Yakov. PureMVC uses mediators, which is a very applicable pattern for the software that produces UI. But would it be that difficult for developers or project architects apply Mediator pattern while designing their business applications as opposed to relying on a framework that implements Mediator globally? Check out this blog on using the mediator. Is it that difficult so it has to be hidden into a framework?

Anatole. ActionScript 3 makes a lot of patterns excessive. A lot of things can be done by using events or dynamic code without really breaching good programming practices. One-liners work for me as long as they are simple and concise.

The main question remains, “Do you want to use intelligent objects that encapsulate most of the framework functionality or if you prefer to deal with simple objecst and do explicit coding for each instance? rdquo;

Yakov. I prefer using self-contained loosely-coupled objects.

Anatole. So, coming back to your question of system-wide singletons hellip; I do not see any reason for creating global objects – they are really bad for both application development process and maintenance in the long run. You can have a singleton pattern inside the models themselves or bind location services with module loaders depending on the architecture of your application.

I have seen these frameworks being used mostly as means to provide project manager/architect with ability to separate areas for developers, quantify functions and make project more manageable. The effect for the resulting application most likely to be negative, but it is very straightforward approach to build systems.

Yakov. So you are saying that utilizing a framework on a project allows create and enforce a nice looking project plan that reads, “Mary will create 10 model objects by February 1, and John will be done with his views a week before? ”

Anatole. Yes, and then we will have all the commands coded a week after that and then we will think about fitting it all together, essentially moving real architectural and design questions toward the end of the project. If you answer the question “How? rdquo; first, people tend not to ask “Why? rdquo; for quite some time. On the flip side, you will have people doing their parts rather quickly thus producing enormous amount of code to fix when the design problems become evident. The problem with formal coding techniques is the human generated code (thus cut/paste errors) without the ultimate understanding how it will be used and very little testing done while writing the code.

Yakov. In the USA, we are already accustomed to protective medicine, when the main goal is to ensure that the patient won ‘t sue you. So when a guy with a headache shows up in an emergency room, they start with sending him to an MRI and making tons of other not too necessary tests. But, it “s better to be safe then sorry… The same rationale here – it ‘s easier to CYA with a nice project plan (see http://www.acronymfinder.com for the definition of CYA).

Anatole. The problem starts MUCH later – at some point of the project the spec changes – business analyst realizes that mistakes were made, process changes, the other department needs some of your functionality or another line of business has to be handled. There is no time compression or shortcuts available there – commands need to be amended and re-coded, views redesigned, events integrated with a different workflow. You are now thinking to yourself, “Why, oh why, did not I go with an application framework instead of the architectural one? rdquo;

The application framework goal is a way to get you through the “implementation ” part faster while giving you maximum flexibility on design and functionality part. If you do not have 80% of application built in 20% of the time, you will be late with the last 20%.

Flex itself is more of an application framework. It is not a library of patterns but rather a set of objects that are built to communicate and react. Flex uses code generators and other behind-the-scene techniques to achieve that. The key here is automation of implementation tasks by minimizing the amount of code while behaving predictably. That is done by explicitly checking the “related ” objects for specific interfaces. By not adhering to the implementation of these interfaces, the external frameworks require serious application development effort to support them.

MVC principals are also questionable in the Web2.0 world. The concept of fine granularity and validation on the client has serious security implications. You go to any AJAX show and you see one or two sessions with security specialists, cracking AJAX sites, getting free airline tickets, buying things for one penny, etc. It seems that every serious organization should be more interested in distributed model rather then pure client side solution. In that case most of the benefits of global MVC go out of the window.

Yakov. So far we have just a couple of the third-party Flex frameworks, but creation of the new ones is a viral thing, and the last thing I want to see in Flex community is more than a hundred of frameworks that do the same thing. We already see it in the Ajax world.

It “s not easy to quarrel when both parties share the same views. We really need other people “s opinions to better represent Flex developers who may see benefits of using frameworks.