Tuesday, December 23, 2008

Some objective comparison of Adobe Flex and Microsoft Silverlight

In the past I've read a number of posts comparing Silverlight to Flex. Often the authors remain very vague on why Flex is better than Silverlight. We all know by now that the Silverlight plug-in isn't near the installed base of the Flash player but there's more than that. Therefore I think it's about time to give an overview of my recent experience.

I've been developing a proof of concept application in Silverlight after having developed the exact same proof of concept application in Flex. Just to be clear: I have much more experience with Flex than Silverlight but I'm pretty sure that the information below is based on facts, not fud.

1. Binding - Both technologies support binding but binding in Silverlight is way more cumbersome. First of all you need a special hack (using StaticResource) to bind UI components together. Even worse is the fact that you need to dispatch property changed events yourself (in Flex you simply specify the [Bindable] attribute on class and/or property level). A direct binding to an expression is also not an option in Silverlight. The fact that there's 2 way binding in Silverlight is an advantage for Silverlight because the current version of Flex is limited to 1 way binding (the upcoming release of Flex has 2 way binding).

2. Data communications - In Silverlight you're more or less stuck with SOAP and JSON for the time being (you could consider using WebOrb or FluorineFx - this gives Silverlight AMF support).

3. Layouting - Thank God there's Flex. Need to layout a data entry form? In Flex you can use Form and FormItem. In Silverlight you need to use Grid, RowDefinition and ColumnDefinition. Not too bad if you didn't have to specify Column and Row IDs because what do you need to do when you need to insert a line in your form... right... renumber everything. There are also no 'right' and 'bottom' properties in Silverlight - pretty annoying.

4. Exception handling - This is a 'bad in both cases' topic. In Flex there's still no global exception handler. Silverlight has one but for some strange reason the screen goes blank after certain exceptions. In other words: there's global exception handler support in Silverlight but it doesn't work...

5. Code behind - To me it's not essential but the fact that there's no out of the box support for code behind in Flex is a pitty. The fact that there's no out of the box WYSIWYG design support in Visual Studio 2008 is probably much more problematic for developers starting with Silverlight (or do you really expect them to constantly switch between slow blend and quick visual studio???).

6. Multi-language - I haven't completely figured out the multi-language support in Silverlight but it's already clear to me that it's way easier to implement in Flex. Just to be clear: the internationalization in Flex is also far from perfect. You need to take care of date formats, decimal and thousands separator support yourself because there's no application global setting in Flex (which is problematic when using validators and binding).

7. Validation - although not perfect in Flex (do they really think all telephone numbers are formatted the US way...), the support in Silverlight is simply absent. You will need to develop validators and the nice red "error tips" yourself.

8. Generics and LINQ - currently there's no support for generics in Flex (actually Actionscript).

What's even worse: there's no LINQ (or something similar) in Actionscript. Silverlight comes with LINQ and that is definitely an advantage (you can't use it for database querying however). Support for partial classes and extension methods is another advantage of Silverlight over Flex. It's clear that we're in need of Actionscript 4 (even if that results in non-compliance with Ecmascript).

9. Components - The Silverlight component set is smaller than the Flex component set (eg. a menu bar component is missing). This might change quicky however. There are already more 3rd party component development companies working on Silverlight controls than companies working on Flex controls.

10. Browser compatibility - Although there are some issues with Flash player running in Google Chrome - the situation is much better compared to Silverlight. That one just doesn't work in Google Chrome.

I'll probably discover more differences during the coming weeks. If so I'll post a new overview over here.

12 comments:

Yakov Fain said...

Nice overview, but I'd like to hear more about features that are better in Silverlight than in Flex.

I'm a Flex developer myself, but find it hard to believe that Silverlight is that behind. Why didn't you compare the tooling?
Flex Builder sucks, that's given. What about Microsoft IDEs used for development with Silverlight?

Palmero Tom said...

To me the Silverlight tooling isn't that fantastic either given the fact that Visual Studio doesn't have a design view of XAML today (and therefore not a decent property viewer). So to me they both s*ck for the moment... It's also hard for me to come up with things that are better in Silverlight given the fact that I'm struggling with what should be straight forward to do. I mentioned some things that are better in Silverlight: LINQ, partial classes and extension methods. There's definitely more for a second post later on :)

Anonymous said...

the current version of Flex is limited to 1 way binding ?

I don't think so, I can use mx.binding.utils.BindingUtils class to do that, it is nothing new since Flex 2. Is Silverlight really do better in this area ? Absolutely NOT.

Anonymous said...

> Silverlight comes with LINQ and that is definitely an advantage (you can't use it for database querying however)

Actually you can use ADO.NET data service which has a RESTful interface to implement a 2-tier solution. The approach is pretty straight forward,

1. Create a proxy to an ADO.NET data service. In Visual Studio you can make it by simply "add service reference".

2. Use LINQ to query against that proxy. The proxy will automatically perform all the LINQ-URI-SQL translation and handle all the client-side/server-side round trips for you.

Similar approaches have been developed in the business application framework in Silverlight 3, if I am understanding right, in which there will be something like shared business objects or data context to further hide the details of data process and transmission between client side and server side. Jamie Cool from MS showed this feature on PDC2008.

Palmero Tom said...

In Flex you can simulate two way binding today by setting up 2 bindings (1 for each diretion). From Flex 4 on you only need to define 1 binding for both directions (http://opensource.adobe.com/wiki/display/flexsdk/Two-way+Data+Binding).

Anonymous said...

You left out one big advantage SilverLight has: multithreading. To me that's a deciding factor on whether a framework is LOB-ready or not.

Palmero Tom said...

Multi-threading is indeed important but less important to me in case of "client-side only" technologies like Silverlight and Flex that support async communications all the way. But I agree that it's something that is missing in Flex/Flash (and I hope it will come one day even though a lot of developers will shoot themselves in their feet).

Anonymous said...

That's nice!! Adobe Flex is really best!!

Scott Barnes said...

I've probably read a 1000 Silverlight vs Flash/Flex blog posts, and typically they always start out the same.

An author is heavily optimised in either product and is branching out in the early days of exploring the product.

It's great that the author is exploring their horizons, but if we based our adoption off first glances at a product then I would of walked away from Flex 1.0 in the early days. As it was expensive and had no real IDE other than 3rd party attempts at making it.

Yet, I didn't, you stick it out as something attracts you to the product and you develop a love/hate realtionship throughout.

Taking a product out on the first date isn't enough, you've got to be committed to its existance beyond your comfort zone.

Otherwise you're just test driving and you'll never really settle on the full experience.

-
Scott Barnes
Rich Platforms Product Manager
Microsoft.

Palmero Tom said...

Hi Scott!

Great to hear from you. I've always liked your online discussions with Ted Patrick. It's hard for anyone to make a really objective comparison given the fact that most developers have more background on one or the other. In my case I was asked to build the same application using Adobe Flex and Microsoft Silverlight in order to be able to compare both technologies. What I experienced is based on the current state of the technology. I 'your' technology advances and I run into another Silverlight project I will definitely blog on it again. The current version of Silverlight however doesn't make me very productive however when I want to develop line of business applications. Just an example: the bugs in the combobox and popup control are driving me crazy. Most of these problems can be solved by relying on 3rd party controls like Telerik. It's sad that they can't 'fix' the limited binding functionality...

facildelembrar said...

I'd like to see a comparison about the size of the generated applications/componentes, etc.

Anonymous said...

I have been working on a LOB application that was originally done in Flex and then as a teaching experience in Silverlight (I was new to Flex when I started this app, and 8 years of C# in both Web and WinForms).

The app originally used a website to query against a SQL Server (SS) that returned
XML. Flex had no trouble binding to this XML and SS is very good at building it up. Silverlight can't bind to this XML; yes you can do Linq to XML but it doesn't support anonymous types (or whatever they are called). I don't want to create a different class for every object that is being returned from SQL; actually I can't since the user drives some of the design.

The Flex dev environment is mediocre but does allow you to design the UI. Visual Studio is a much better dev environment but the addition of Blend takes it a step or 2 back. Yes the designer support is better in blend, but creating a UI with the lack of controls in Silverlight is like going back and designing forms in C++ compared to VB6.

The lack of support with XML is the biggest issue that I came up with; I don’t want to create objects. I want to consume my XML via binding and send it back up to the server to perform DB updates. Microsoft is really pushing the RIA Services and the model we have been following for years is to handle all database activity in stored procs mainly passing XML around. How many applications are written where 1 table is updated at a time like CRUD likes to do. Almost all of the designs I work on have forms that encompass multiple tables that either are related via a foreign key relationship or are lossly tied via some other means.

Datasets are another method of retrieving and processing data and Silverlight ignores that one also. I did use the Silverlight Dataset objects from VitalyL via a WCF service. It worked, but seemed to have trouble with twoway binding.

Overall I was disappointed in working with Silverlight (I really wanted it to shine). However, Microsoft has the biggest share out there in the dev world and will probably become a bigger player in the future in this arena. It would be dumb to not push forward and learn Silverlight. Companies will keep choosing them in the future but Silverlight may take a while longer to really catchup and take over Flex for developing applications quickly.