Testing Flex RIAs: The Aftermath

On August 12, I participated Farata’s symposium for Enterprise developers for the second time. But unlike the first time, I was on the other side of the barricades. I presented my research in the field of functional testing of Flex-based RIAs. Since my previous preso at NJFlex user group, I  figured out how to include automatic functional testing in enterprise application development life cycle.

In these presentations, I demonstrated what a Flex developer needs to know to prepare his or her  application or even a single component to painless UAT or QA testing. Using the tool FlexMonkey form GorillaLogic I demonstrated the basic concepts of interaction with Flex Automation API and components instrumentation. And for dessert, I showed how to automatically run functional and unit tests  on each code commit to the version control system. The screenshot above is an illustration of what I was talking about – instrumentation of components, introduction to FlexMonkey – an open source Flex-enabled testing tool, and Jenkins – one of the best open source continuous integration servers. The entire enterprise RIA development cycle was sampled.

Stop! Why am I trying to write the transcript of my preso?

If you missed the event, you still can download my presentation slides from here. Find the sample source code here. And ask your testing-related (or not) questions in the comments to this post.

Cheers,

Vik Gamov

Adobe Flex DataGrid with 4 million rows

If you already upgraded your Flash Player to 10.2, take a look at this little demo, which has three Flex DataGrid components. Two of them on the left are good old mx:DataGrid and the one on the right side is the extension of new spark:DataGrid available with the recent Flex SDK 4.5 drop.

All the UI controls share our custom implementation of IList/ICollectionView and are able to show 4 million records. Actually, with mx:DataGrid you can go even further and display 10 million records. As a side note, if you stick to MX-only components, the example may be compiled with Flex SDK 3.4 and work with older version of the player.

The spark:DataGrid is a more complex case. First, unlike with MX equivalent we have to subclass original component to add scrolling event. Second, it seems that Spark GridLayout has overflow errors when calculating layout for the dataProvider of approximately 5 million records and above — hence the limitation of mock data set size in demo.

Finally, there is an error with fast scrolling using scroller thumb: after thumb-scrolling spark:DataGrid it’s necessary to move up/down with scroller’s arrow keys otherwise Spark grid would repaint itself after scrolling of mx:DataGrid-s. We are working on this issue – most probably our extension either misses a thumb scroll event or needs to be better synced with the scrolling events.

Don’t try it at home with the default IList implementation (ArrayList) – it’ll eat up all your memory.

Valery Silaev

RIA Integration: Bits and Pieces. Part 1.

There are many ways to have various software components to communicate in Java EE enterprise architecture.  The same is applicable for integrating rich Internet Applications written in Adobe Flex and Java EE systems. Let’s consider the following scenario:

An application A is being developed using Flex-BlazeDS-Java, and it needs to integrate with a third-party Java-based Web application B, where the users must register, otherwise they can’t continue using the application A.
Of course, to implement this scenario you can engage some of the business process management software packages that will allow you to describe and configure the workflow with minimum or no coding. But the less moving parts are used in the architecture the better. Here’s the pretty simple way to implement our scenario.

Step 1. When the user presses the button on Flex view, the code is being executed inside the virtual machine – Flash Player, which in turn is sitting inside HTML wrapper.    So the first goal is to make a call from inside the Flash Player to the outside world. Using the ActionScript class ExternalInterface you can map the internal function, say registerUserAS() to the wrapper’s JavaScript function registerUserJS(). You have to write both of these functions yourself.

Step 2. The JavaScript function registerUserJS() opens the URL of the application B in a separate Web browser window, where the user registers as required by the application B.

Step 3.  In the application A, develop and deploy Java servlet, say RegistrationCompleteServlet that can be called by the application B when the user successfully completed the registration. During this call, the application B will pass to the servlet a Data Transfer Object  RegistrationInfoDTO, with all required registration details.

Step 4.  The RegistrationCompleteServlet and BlazeDS are collocated in the same Java Servlet container(e..g. GlassFish, Tomcat, et al). The RegistrationCompleteServlet initiates a push of the RegistrationInfoDTO to the BlazeDS destination RegistrationDest with the routing to the proper client. How to push the data to the client over the AMF protocol is described in our book Enterprise Development with Flex.

Step 5. Almost forgot to mention that during the startup, our Flex application has created a Consumer subscribed to the messages from the destination RegistrationDest. As soon as the RegistrationInfoDTO is published to this destination, Flex client will receive it and let the user into the next view with a nice greeting, “Thank you, Yakov for registering. Your credit card information has been validated”.

That’s’ all there is to it. I’ve included “Part 1” in the title of this blog, because hoping that this will become a series of writeups on integrating Flex and Java EE.

Yakov Fain

Hacking or Design Patterns?

Earlier this year, I made a statement defending hacking in an interview for Oracle. Yesterday, I found a thread on theserverside.com where java developers were sharing their view on the subject. In this blog I’ll take the same two quotes there ignited some arguments and will try to explain my point of view.

1. “Recently, I’ve been running a seminar for a small group of Java developers. Several times they’ve asked me, ‘Is this code an example of MVC pattern?’ I got the impression that implementing MVC had become an end in itself. Using Design Patterns is not a dogma. Just write the code that makes sense. Not everything that makes sense has a named design pattern.”

2. “Abusing design patterns is not always the fault of Java developers. I find the approach used in the enterprise software shops similar to medicine in the US. In my opinion, lots of doctors here practice ‘protective medicine.’ They are trying to protect themselves from malpractice law suits. Enterprise managers and tech leads also try to minimize the risk introduced by lower-skilled developers who are part of every team. Yes, abiding to object-oriented principles definitely helps in making code readable, but this does not always translate into better performing applications. If hacked-up code produces great results, apply it without worrying whether another developer will have problems understanding it.”

I work for Farata Systems, a consulting company that makes a living by developing rich Internet applications utilizing Adobe Flex and AIR and Java EE. We are a small company (about 30 people). We do consulting as well as develop our own software (both commercial and open source).  The number 30 is important here. Many years ago, a respectful person taught me that until the company is under 30 people it’s efficient because there is no need to hire middlemen managers. The founders of the company can run the projects themselves, and there is no ballast.

After several years of running the company with two other geeks, I couldn’t agree more.  We can afford to cherry pick developers, which large company can’t.  I’ll tell you more – we can afford having people who don’t have to stick to design patterns just to ensure that Joe Smith who became a programmer after attending 6 months of vocational school will understand the code. We can afford to build teams not with code monkeys who were shoved into our throats “because XYZ is our offshore partner and we have to keep them busy”. We are also working with offshore developers, but only with those who can do the job and can read/write the code regardless if it belongs to M, V, or C tiers.

Design patterns were not created equal. It’s OK to bash Singletons.  They are easy to be blamed for being a replacement for global variables. But MVC is still considered to be good.  Unfortunately, it’s not about three tiers any longer. Java architects enjoy creating layers. They’ll be happy to explain anyone how these extra layers will make your application very configurable and flexible. Layers are best friends of consulting firms who have sharpened their skills in creating beautiful powerpoints with nice round-square rectangles filled with color gradients. Thick arrows going from left to right shows how “with our consulting company you’ll move from here to there in just a couple of years”. The arrows must leave no doubts in the minds of hiring managers that “these guys can do it”.

And most importantly, these multi-tiered diagrams will explain the hiring manager of a large corporation that it’s OK that Satish is weak on the front end and Boris never worked with the back end…if you know what I mean. This multi-tiered design can turn both Satish and Boris into code monkeys who will do nothing but inserting their business logic into easy to understand location and the framework will do the rest. Design patterns promote the lowest-denominator-skills software development.

You may be surprised, but even such a sacred cow as dependency injections is not a must. Believe it or not, pretty much any application can be created without DI. I’m not kidding. No XML configuration files to process. Popularity of dependency injection in the middle tier is based on the necessity of integration techniques to allow upgrades and replacement of large pieces of technology with their new implementations. To be fair, I need to praise Java EE 6 for smart and light implementation of DI that doesn’t make you drown in XML.

Applying DI in the front-end applications on top of the frameworks with well designed event model is an overkill on the desktops and suicidal on smart phones and tablets that need to be optimized for memory and speed. We see bigger consultancies still doing it because it is a proven and easy to sell solution. Unfortunately, starting a new Flex project with an analysis of which MVC framework to choose seems to become a habit in enterprises.

My interview statement that writing the code that works is the ultimate goal is applicable only in teams that can afford to employ skilled professionals. If for whatever reason you can’t, go with the flow and rely on injections that somehow will put the collection of Orders into your Customer object.

Finally, to make this blog even more thought provoking, I’ll touch upon yet another sensitive subject. Who do you need to write code for – humans or computers?  On one hand, the code must be readable, cause the same piece of code is being read a lot more often than being written/modified. On the other, the code must be efficient.  For example, in financial trading applications adhering to design patterns is a low priority item. Speed is the king there.
Recently, I showed one chapter of my new Java tutorial to a very experienced Java developer. He was surprised that I included an example of BitSet there. This is what he said – word for word, “Perhaps your experience is different than mine, but I don’t think I’ve ever seen this class used in practice. It really feels a bit old-fashioned, and C-like. In 2010 I’m not sure anyone writing code in Java really worries about this level of saving bits. Maybe it still relevant in some embedded systems, but do those systems actually run Java?”

Ten years ago I was working on developing an equity trading system for a Wall Street company.  It was a J2EE application with a heavy use of messaging. A trading order had to be sent to a queue, and this was an object with about 50 fields with yes/no values.  Using BitSet for sending a set of flags (bits that are set to 1 or 0) instead of text or numbers is the most economical way to do this. Did I care that a programmer who’d be reading my code a year from now won’t immediately understand that just a couple of bytes carried had tons of information about the order? I did not. This piece of code was not readable, but efficient.

IMO, in the ideal world of inhabited by skilled software engineers, the code has to be written for computers. But we don’t live in the perfect world. So I don’t insist.

Yakov Fain

Flex Camp Wall Street – next Monday

A good mix of practitioners and Adobe Evangelists will be presenting on various topics related to using Adobe Flex in the real-world projects. Farata Systems will be represented by Victor Rasputnis and myself. Hope to see you there.

Victor will show you how to generate complete CRUD Adobe Flex/BlazeDS applications based on Hibernate framework on the Java server side. Clear DataBuilder Eclipse plugin will assist us in annotating Java interface without the need to do manual coding and configuration. You will see remote lazy loading of the collections, server-less transactions controlled from the client and, integration with Adobe Fiber – a model-driven development environment of Adobe LCDS… but with BlazeDS.
I’ll talk about making networking of Wall Street applications reliable with BlazeDS. Loosing a trade order is not an option. But using free and open source BlazeDS for Flex/Java communications doesn’t guarantee 100% of all your clients’ orders will reach the destinations. This talk is an overview of networking problems of Flex-BlazeDS enterprise applications with the demo of the error-emulating protocol, which concludes with introducing of reliable AMF channels.

Visit the Web page of Flex Camp Wall Street for more details.

Yakov Fain

The workshop on auto-generation of Flex/BlazeDS/Hibernate CRUD

The workshop on auto-generation of Flex/BlazeDS/Hibernate CRUD with CDB is uploaded in General Docs at Sourceforge https://sourceforge.net/projects/cleartoolkit/

Hibernate support has been introduced in CDB 4.1. If you are interested in SQL or POJO-based generation, stick to the previous version of CDB and refer to the CDB 4.0 workshop PDF, which is also located in General Docs.

I’ve recorded screencasts. The first screencast is about supporting entities in CDB 4.1. It starts from the finished application and then I explain how it was generated. The second one is about using hierarchical collections with entities.

Victor

To use or not to use Flash/Flex portals for Web sites

Last week I was thinking about design of the main view of a new project for a new client of ours. This application is interesting in that it can deployed as an enterprise RIA as well as a tool to be used by any consumer connected to the Internet.

The mockup of the main view looks clearly like a Web portal with a number of portlets, which can be maximized, moved around, and independently communicate with the server(s).  But… This Web site has to be discoverable to bring more and more new customers.
Here comes the quiz. Can you see why the previous two paragraphs have an important logical issue, which represents a misconception sitting in minds of many creators of Web content?

Being a Java developer, the JSR 168 is always in my mind and the first annoying thought is, “I can create a traditional HTML/JavaScript Web site with portlets, some of each are Flash Player SWF’s and the others are regular HTML/JS markup. This will give to search engines enough of a textual chew to digest plus the benefits of more animated, engaging, and better performing (sorry, Steve) Flash content”.  If some of you want to bring these dopey and groundless Adobe statements that Google is indexing Flash content with special secret, mighty, but headless Flash Player, please, get real or show me the money.

I know how to create a well looking and performing Flex/Flash based portal. I know how to cut this RIA into pieces, how to run this project, how split the job between team members located all around the globe. I don’t know just one thing – how to make this Flash-based portal d-i-s-c-o-v-e-r-a-b-l-e on the Web.

And here comes the answer to my quiz. Stop confusing Web sites and rich Internet applications! Got it? OK, let me re-phrase it. A Web site and RIA are created for different purposes.  Creating an HTML/JS Web site to present, promote, and make discoverable your RIA is one independent track of your project. And a-f-t-e-r the random user somehow landed on this Web page offer him or her a little link to the real beauty – a Flash-based (sorry, Steve) portal.

That’s all folks. It’s Sunday morning, and I need to go out and get some stuff for the barbecue – having more than 20 people over today.
If you want to discuss it in person, consider attending our Third Annual Enterprise Flex Symposium in New York City. It’s a small event where attendees and presenters can have face-to-face conversations.

Yakov Fain

Enterprise Development with Flex

It’s been almost four months since our book “Enterprise Development with Flex”  been released in print by O’Reilly.  Since day one, it remains in Amazon’s bestseller’s list in several IT categories. This gives me a great feeling given the fact that Amazon re-calculates their stats hourly.
I’d like to share with you some interesting facts that from the times when this book was in its proposal stage. If you carefully look at the book cover, you’ll notice a little logo and the text Adobe Developer Library.  To earn the right to be included in this library our book proposal had to be approved by Adobe engineers. We made it, and are grateful to excellent software engineers from Adobe Flex team, who put their trust in our ability to write such a complex and advanced book.

After the approval process was done, O’Reilly sent us the Flex team members feedback without revealing the names of engineers who wrote them. Most of them were 100% positive. But our special thanks go to one unknown member of Flex team who wrote something like, “I don’t agree with many of the things that these authors write about Flex in their blogs and articles, and I’d rather not approve them, but I will because there are not many people in the industry who are capable of writing such a book.” We don’t know your name, but we consider this assessment to be the best compliment we’ve received so far.

Looking forward to meeting with the members of Adobe Flex team in October at MAX conference.  The authors of this book are going to attend this event in LA in October.

Our praise goes to the O’Reilly cover designers who correctly visualized three authors of this book without ever meeting them in person.

If you bought this book, Farata’s team would really appreciate if you’d spend 10 minutes and publish your review of this book on Amazon. It doesn’t have to be long, but we are looking for getting your honest opinion about our work.

Your truly,
Yakov Fain

Disappointed with Adobe

Was not planning to write this post. It was ignited by the  “Disappointed with Flex” article posted by Valery Silaev, our lead Flex/Java developer.  I’ve been working with Valery on a couple of projects. He’s good software developer. And when he says that he’s disappointed with Flex 4, you should listen.

I really value people who speak up freely and have something to say. Valery is disappointed with Flex 4, but I’d like to take it one step further. I’m disappointed with Adobe.
To put it simple, Adobe is sloooooow. I mean really slow, and I’m not sure what’s the reason.  I know some people from Flex team. They are smart. They can deliver given the right support from top management and proper investment, which is definitely not there.

Let me build the case. Slowly.
Four years ago, when Adobe purchased Macromedia, I was looking for a decent tool for development of the enterprise Web applications.  At that time I was disappointed with Java Swing. Wrong decisions at the top level of Sun Microsystems resulted in having 75% of the computers running Internet Explorer with… ten years old Java run-time. Sun Microsystems won the lousy $10B law suit with Microsoft back in 1998, but lost the battle. Their runtime (yes, the JVM) is not installed at the consumers’ computers.

Four years ago, Adobe’s Flash Player (it’s a VM too) gave me some hope. The runtime was there, the library of rich components  was there too, installing Flash Player was piece of cake. I started working with Flex.

This new for me Flex/Flash community was a bit unusual after Java. It was small.  I had a feeling as if we are in a small country club chanting, “We are the best”.  Flex developers knew each other by names. Adobe Flex technical evangelists were Gods. This was different from Java community of six million of professional developers.

But Adobe didn’t have competition in the area of enterprise rich Internet applications in 2006, 2007, 2008… Until the greatest “Me too” firm from Redmond, WA realized that RIA is the right place to be and IE is not the only browser people have. They started working on this Silverlight thingy. Two years ago they released the 1.0 version that could be ignored – nothing but video streaming was there. At the same time Adobe released Flex 3, which had pretty much everything: 98% penetration of runtime, rich library of components, fast communication protocols, and the server-side component LCDS, that nobody but filthy rich Wall Street firms could afford.

Two years later, Microsoft released three more versions of Silverlight, and the only thing that stopped them from presenting a serious threat to Flex was low penetration of their runtime. Microsoft has tons of cash and excellent engineers. During the same period of time, Adobe has released Flex 4 in hard labor. It took Adobe two years to release the next incomplete version of Flex. Why?

Being a Java developer, I was watching closely the evolution of JavaFX, yet another wannabe player in RIA.  I clearly a similar pattern there. Top-level management proclaims at every keynote that “We are the best” without giving enough juice for engineering teams that work hard developing a product.
The bad guy, Steve Jobs, doesn’t even know what Flex is. He’s not happy with Flash Player. Need to admit, he’s not playing by the rules trying to say that Flash Player is junk and a main reason that crashes the OS. He’s bad, but he’s not stupid. Adobe couldn’t offer a better response than “We love Apple”.

Yes, Flash Player is installed on 98% of desktops, as if we don’t know that not many consumers are using desktops today, and in five years they will become minority.
Steve Jobs, the bad guy, made Adobe moving just a little bit faster and they finally released Flash Player 10.1 in 18 months (!) after the 10.0 release.

Two years for the next and incomplete version of Flex. Eighteen months for 0.1 upgrade of Flash Player. Dumb pricing policy on LCDS that makes it unaffordable for even a small group of loyal customers. Not a Wall Street giant? Get out of here. Is this the way to treat customers?
Let’s get back to the tooling. This smart idea to bring together designers and developer gave birth to yet another prototyping tool called Flash Catalyst. Is it more than just a prototyping tool? Tell me why?

Here comes the Flash Builder (formerly Flex Builder). Flash developers (they haven’t seen any better) were so happy with Flex Builder 3… From the Java developer’s perspective, this was a mediocre and damn slow Eclipse plugin. Flash Builder 4 after two years of development was not a major improvement either. I’m not sure why JetBrains doesn’t want to invest a couple of rubles and add a WYSIWYG designer for Flex. As soon as they do it – Flash Builder is brain dead.

The next target is Flex 4 SDK.   The new Spark library of components with separating the functionality of components and their skinning implemented just half of the components comparing with Flex SDK 3. In two years they could have done better if they were a large company catering for developers.  But they are not. Until Photoshop and PDF remain their main source of revenue, the tooling for software developers will be pushed aside.

Adobe was and remains a small company. They do what they can.  And it doesn’t seem that they can do much more for us, developers.

Yakov Fain
P.S. This is my personal opinion. My employer may think differently.

Disappointed with Flex 4

After spending some time working with Flex 4 on a real project, I can’t say I’m happy with this product. My list of complains  is based on moderate sized project, 5 months, 4 developers, WebService-only back-end.

1. Flash Builder 4 has lots of issues – more than Flex Builder 3. AS of today it has lots of bugs:
-it doesn’t release resources;
-debugger does not allow to run several instances and consumes a lot of resources;
-debugger intercepts all network calls and the debugging proxy is terribly slow and inefficient;
-code navigation between several projects is absolutely impossible;
-compiler is unpredictable and slow;
-it periodically tries to do incremental compilation, even if you explicitly tell it not to do so — and you have to disable incremental compilation, because it’s slower than full rebuild of all related projects with Maven.
-Help system is not well designed — Adobe moved help to a separate AIRr application, in-place contextual help is non-existent; search always shows one link — “yes, there are probably some topics for your query — open separate application to search again”

2. Flex compiler is broken
It’s slow. It’s slower than any previous version I’ve used. And it’s buggy. Periodically it shows some cryptic messages like “there is no x or y or width or height properties on UIComponent”. It never points to exact source of problem — and I doubt it exists. Because sometimes fix is to set “-keep-generated-actionscript” flag on. And sometimes off. And if it doesn’t help then the fix is to reorder attributes in MXML tags. Just insane. And I can’t find the exact root of these messages, the only thing I can say for sure that they are caused by new MXML skins — no skins, no errors.

3. The new Spark library is over-engineered.
I worked on some Java Swing projects some time ago. It seems that Adobe takes the Swing route, however Flex becomes popular just because of the opposite — it was way far simpler than Swing. Flex ideology was “keep simple things simple, make complex things possible”. Now it turns to be the Swing ideology: framework usage is irrelevant, the only relevant thing is framework per se, and it should be perfect.

I can’t do a lot of things with Spark I was able to do with MX. Icons in buttons? Develop descendant component of Button, define new parts and develop separate skin. ComboBox where items in drop-down are large than input field? Develop own skin — just copy-paste and tweak a bit. Paddings? What paddings? It’s not a css attribute any longer, extend and develop own skin. Left/right/top/bottom? You can’t customize this via css, or develop your skin if you truly need this option.

But architecturally Spark is beautiful, no doubt. Astronauticaly beautifull architecture, if Joel Spolsky permits me to use this term.

4. New Spark library is incomplete.
Yes, this statement doesn’t contradict with [3]. Being overdesigned it’s missing a lot of functionality from MX: no Calendar, no DateInput, no ColorPicker, no PopUpButton etc. No clone for MX SWFLoader/Image. There is no complex containers at all (like Accordion and TabNavigator) Needless to say, there is no advanced controls like DataGrid and the supplied “proxies” for ItemRenderers confirm that there are will be none any time soon.

5. New states engine encourages unmaintainable code
Previously we have states with explicit overrides. All data related to override was co-located, so it was easy to see what and when changes. There were inheritance of states, and it was sufficient. There were no groups, but when you need state groups — then 99.9% of times you in fact have to extract part of component as sub-component, and coordinate isolated state changes there. But now the great property.inStateFoo=”xyz” notation comes.

Now you have to scan over tens or hundreds of lines of code and check all and every includeIn / excludeFrom attribute and decompose them back to the very same old “overrides”. In short, when you are debugging states you have to do job of compiler but without the help of compiler. And the existence of state groups multiples the complexity by the factor of ten. It’s a Ruby-way productivity — it’s easy to develop a sketch / prototype, it’s a nightmare to polish this sketch to be a real product and it’s absolutely impossible to support it. But sure, you can start quickly, who cares about the rest…

6.  Vectors (Flash-10 related, not just Flex 4)
Vector is a canonical example of a half-pregnant woman. Hey, developers! Use new features –  Vectors and Generics (or this is templates??? we are not sure on our own). Yep, it’s cool, Vector is a parametrized type. Though, there is no type covariance/contr-variance and no type bounds in syntax. So you have to cast data Vector whenever it’s declared as parameter or as a return value. But who cares?

7. Text engine (Flash-10 related, not Flex 4 only)
It’s great that “Gordon works on text”, and new engine is indeed superior. But may we have both Spark and MX on same engine by default without the dual way to embed fonts and dual size of embedded fonts?

Am I missing something?

Valery Silaev