Friday, June 13, 2008

Web development: ASP.NET Webforms versus Rails, Flex, PHP and Java stuff.


Some History:

I am a long time web developer and making a living from it. For my entire programmer life, I looked for perfection for developing applications. I remember back in 2002, I was struggling about if thick clients or web clients were better for typical form processing. At that time richness of thick clients were more attractive than these days since we did not have all ajax goodies, flex, silverlight etc.

Time passed and I decided to go for web apps. and I have no regrets so far. Not that I am claiming it is a better way but I am just happy for my personal development.

Then came the next question: I need to go with some platform/framework etc. I've worked with a lot of technologies: ASP, ASP.NET, PHP, Java frameworks (Wicket, struts, Echo, plain JSP) , Flex, silverilght, Perl CGI. I felt uncomfortable with the number of choices since it is impossible to specialize all of them and it was extremely hard to predict which of these technologies have a future (and even now). Selecting a technology is difficult, you need a very good eye for that. Common sense says: "use right tool for right job". And yes frameworks are tools. But unlike that analogy, these days frameworks are so powerful that most of them claims to be suitable for "every job". For instance, you can write executables with PHP, you can write desktop applications with Flex via AIR and with .NET and Java you can do almost everything you can imagine and even you can write operating systems with them ( SharpOS, Cosmos, Singularity, Jnode ).

I started web programming with Perl /CGI then I quickly moved to PHP and then Java and then as a requirement of my job I first met with ASP.NET 1.1. And I hated it. Then came ASP.NET 2.0. I was extremely impressed with ASP.NET 2.0 at that time. It really seemed to me that
MS really did a good job with it. But after sometime passed, I missed neatness and good design in Java frameworks. ASP.NET 2.0 was very practical but it completely ignores good design practices which leads to unmaintainable crappy code. Specifically talking about webforms since it was the only thing running on ASP.NET.

Finally, I've met Ruby on Rails. I've done some projects with rails and I really really liked it! Everything smells correct with rails. And it is much easier than java or .net. I also like linux so I thought I was finally off the MS lock in. However, later while dealing with ruby, I start to feel uncomfortable on things like dealing HTML manually , unicode problems, and green threads. It was painful to use a multi select html selectbox with rails where you use nested arrays for that and it looks ugly.

Finally I returned back to ASP.NET forms but with a different eye! I quit following MS practices ,instead I applied things that I learn java and rails. I feel much happy now and Webforms is my favorite platform. This article will be comparison of webforms with "others" based on my personal experience. I might be wrong so feel free to correct me.
But first lets dispell some myths:

Myths for ASP.NET Web Forms:

ASP.NET runs only in Windows: This is a major problem to many people. I am a linux fan and I use linux and develop on linux everyday. And we have great Mono project runs asp.net successfully on every platform. It is quite up to date too. Everything works there including Ajax, Ajax control toolkit, asp.net futures, asp.net mvc (although illegal to do so) . The only missing parts is Web parts and the new listview control (listview implementation is underway!).

ASP.NET Web Forms are easy: Unlikely the demos made by MS, dragging and dropping stuff, ASP.NET is extremely complex, but also powerful.

You can only use C# and VB with ASP.NET: You can use C#, VB.NET, IronPython, IronRuby, Boo, Nemerle with ASP.NET. There are possibly others but these are the ones I know working.

Pros for ASP.NET Webforms:
  • It uses .NET platform so entire .NET library is at your command.
  • Extremely well documented and main stream
  • Cross platform. With mono it works everywhere
  • Mono ASP.NET is open source
  • Component and Event Driven, so you are not usually messing with Javascript and HTML
  • Ajax is extremely easy. Use an updatepanel and you are good to go
Cons for ASP.NET Webforms:
  • Can be extremely complex. Loading dynamic controls on runtime , view state issues , custom controls , ASP.NET Page Life Cycle are too complex. I mean it!!!
  • Viewstate! It helps a lot to emulate a stateful web. But it can be a true performance killer if you are not careful
  • Generated HTML : ASP.NET generates complex html that doesn't play with other things easily. You can catch yourself dealing with ctl100_xxx_yyy type of Id's. CSS and Javascript can be painful too. But ASP.NET webforms philosophy is different. you have to get it really!!!
  • Hard to unit test. I was really puzzled for this. Unit testing is important. I invented my own Model View presenter pattern to get around this issue.
Even though that cons I still like ASP.NET Webforms best. It is extremely powerful if you know how to use it correctly.

And now the comparisons:

ASP.NET WebForms versus Rails:
I really think asp.net is superior to rails. Firstly, when you develop an n-tiered web application, it doesn't have to be a web application at all in future. That's why we have n-tieres. We could replace the UI layer with any other thing. You can convert it to a thick client application a socket server or what ever you like. Rails is a web framework period! You develop a web application and you have to live with it. Most of the time this is not a big deal since your purpose is developing a web application anyway. But I like the flexiblity of n-tiers.

Secondly, Rails, actually ruby has no real threads and it is 200x slower than C code. In fact,this has never annoyed me in practice but I feel more relaxed that I could use real threads with .NET. Additionally, unicode is breeze with .NET where rails fail miserably.

Rails use a template approach that if you intended to generate html pages, which gives you a nice clean seperation of your ui from controllers. But you have to type a lot of html and yes I am aware of HAML. ASP.NET allows you to build components and those components can talk each other with events only. This leads to a very good isolated design. Also things like output caching allows you partially cache some parts of your pages. I see no equivalent of this in rails.

Furthermore, Rails' Ajax is not as easy as asp.net. You deal with RJS templates although you can use things like JQuery or Ext or YUI , that way you make a language switch.

Ruby is a better language than C# imho. C#, although 3.0 version is fantastic is a bit verbose compared to Ruby. But I still like C# very much. But if you want power there are much better languages than ruby in .NET/Mono world like Boo and Nemerle. They are extremely powerful and you can develop asp.net apps. with them.

And for backend, Rails has ActiveRecord but so does ASP.NET: Castle ActiveRecord.
And even with .NET you have something better than Activerecord . Enter DB4O!
No more mapping , with db4o you can truely ignore you persistance layer and store your objects as they are which is difficult to implement with rails.

Another point is internationalization, and multi langauge applications are very easy with asp.net via Resources. Rails has globalize plugin for that and works well but it creates some messy tables in the db.


ASP.NET WebForms versus PHP:
I am sorry for PHP fans but syntax is really ugly. PHP doesn't feel like an OO language. PHP 4 was an hybrid lang and PHP 5 implemented full blown OO stuff. But still I don't feel OO paradigm with PHP. It also suffers the same problem with Rails. Too much dealing with HTML. PHP has rails like or even ASP.NET like libraries. But still too low level for my taste. One good thing about PHP is it's extremely wide-range of library support. Other than that I see no reason to you php except for dealing legacy applications.



ASP.NET WebForms versus Java stuff: JEE versus ASP.NET is a long time debate actually. Java has a lot of decent web frameworks. They are mostly component oriented like asp.net. I can't bash them but ASP.NET Webforms looked much better than JSF, struts. and yes .NET has NHibernate and Spring .NET. Also C# is a better language than Java (just side by side language comparison not runtimes!).


ASP.NET WebForms versus Flex: Flex is extremely powerful. And it archives things that ASP.NET can only dream of. Very componentized, very elegant! The only thing I dislike about Flex and disconnected frameworks like ExtJs or Qooxdoo is that you have to serialize your Domain entities. And if you have bi-directional associations those objects cannot be serialized into JSON or XML. WCF provides a workaround for that but I doubt it will be useful with anything besides .NET. Then you have to build with DTO's. Same problem happens to be with Rails + Flex or Rails + Extjs. Rails creates DTO's on the fly with toXml or toJson thingies.

ASP.NET WebForms versus ASP.NET MVC or MonoRail:
First it is illegal to run ASP.NET MVC on linux so you are locked into Windows. Second ASP.NET MVC and Monorail although can use ASP.NET components they cannot use Postback controls. Then you drop to HTML once more for many things. Ayende "The Great" (that's what I call him), rightfully complains the complexities of WebForms and he prefers MonoRail . I can totally understand him. His points against web forms are valid. But I think this is a matter of a personal preference when you compare pros and cons.

Well this is the end. Feel free to criticize and correct me. Happy web programming !






18 comments:

leonardoavs said...

La comparación con Java es pobre y si .net tiene spring e hibernate pero nunca al nivel de desarrollo con los frameworks de Java. Si asp corre sobre Linux pero lo que no se dice es que las librerías están hechas por MainSoft compañía que desarrollo el código de esas librerías para que con su compilador transforme el código c# a bytecode y así puedan correr en Java ósea Asp.net 2.0 corre en Javs. JSF no es como asp (Desde su inicio fue pensando MVC vea Oracle ADF que son componentes JSF que pueden correr en un TelNet, en un Movile, en Internet explorer 7.0 etc). Y si solo se queda sin ver los frameworks como spring MVC o Jboss Seam no se está haciendo nada. Sé que la comparación anterior es desde su punto de vista pero no hay que ser tan ojos cerrados con M$. En conclusión Java y .net son grandes plataformas y no hay que hacer una comparación tan pobre de ambas. Vea (Tapestry, JBoss Seam, Wicket, Spring MVC)

Onur Gümüş said...

In a point I admit, the comparison of Java with java frameworks is rather poor. Java frameworks are not bad. So I am not bashing it.

However you are extremely wrong at one point. ASP.NET runs on linux without any libraries of Mainsoft and without java. Mono project is an alternative to MS .NET framework. If you read above you will see it.Mainsoft is an alternative to this methodology. One thing, the Ajax library of mono is developed my Mainsoft. But it does not require java and is a part of Mono.

Coming back to Spring and NHibernate, actually .NET world has better options than Spring.NET like Castle Windsor. And yes NHibernate is not as comprehensive as Hibernate 3.0 but it supports things like Linq to NHibernate where java only can dream of. I found NHibernate sufficient.

Lastly I am not blindly following MS. Because I don't use anything belongs to ms. I use linux, at work and at home . And I develop ASP.NET on linux without java. Period!

Thomas said...

This was a really cool and neutral comparison without all the usual FUD and language/platform religious stuff. Great write up :)

PS!
I work for Gaiaware, the guys behind Gaia Ajax Widgets and with the list of "ALT.NET stuff" you're using in your toolbox, I would bet you would definitely like our stuff :)

Anonymous said...

One big thing you might be missing that is important for a lot of people, is the tools available.
I might be wrong about this, but from a developer's perspective MonoDevelop is still lacking compared to the VS offering on Windows.
One nitpick:
"tired" -> cansado
"tiered" -> capas/niveles

Anonymous said...

ASP.NET may well be the best framework for helping users paint stateful web applications in a builder tool using powerful pre-built components. As you say, it does however have its disadvantages.

A completely different approach to building complex stateful web applications is Wicket. It gives up many of the advantages of ASP.NET (Wicket presumes a developer who is expect in object orientation, and who is comfortable expressing designs via code), but avoids many of ASP.NET's disadvantages.

Creating and using custom controls, and loading controls dynamically by the runtime are as easy to do as with Swing desktop programming. A great deal of AJAX can be done via Wicket components without the need to write JavaScript. Unit testing is well integrated.

Not only does Wicket makes it easy to keep business logic out of the HTML, but presentation logic is also kept out of the HTML. _All_ logic is programmed in Java (no tag libraries and no embedded scripts). The ease of building custom components makes it easy to follow the Don't Repeat Yourself principle when implementing the user interface. (My impression of the ASP.NET philosophy is, "We expect you to repeat yourself from page to page, but we'll try and minimze the labor of doing so." Wicket's philosophy is, "We'll make it easy for you to abstract out repetitive patterns wherever you find them, using the full power of object-orientation.")

Someone who likes ASP.NET will probably not like Wicket, and vice-versa. But it's worth investigating Wicket, if only because it represents a completely different approach to building the same kind of applications.

Anonymous said...

I've never liked the phrase ".net framework", because .net isn't a framework like ruby-on-rails, symfony or spring. ASP.NET competes with J2EE, PHP and ruby, but not with web app frameworks. In fact, ASP.NET is a great environment to develop higher-level frameworks in, just like J2EE and PHP.

I've never had much patience for the web controls, because they aren't compatible with the modern way of web programming that people call "MVC". Basically, the web controls assume that 1 ASPX file == 1 web form. A modern web application needs the ability to display different views (often forms) depending on the results of processing a form, and the web controls don't do hat in a a natural way.

It's a shame, because the syntax web controls are more elegant than the 'helper' methods that people use to attain similar goals in most frameworks. I'm pretty sure that somebody could make a set of web controls that really work, but I haven't seen it.

The web controls feel like an attempt to outdo Cold Fusion and JSP -- like a very advanced last-generation system, rather than the kind of current-generation system that people are building with RoR, symfony, Spring et al.

The good news is that .net programmers have a great base to build modern frameworks. The bad news is that a lot of programmers with a background in the Microsoft world are reading books about how to write last-gen apps in ASP.NET , drinking the kool aid, and building apps that they, their employers, and the users of the apps will regret -- rather than wishing they were programming some cool like RoR, they should learn from other environments and build a next-generation system that rocks.

Onur Gümüş said...

@thomas:

Thanks. I am well aware of Gaia Ajax framework. I've even submitted a small bug fix for your calendar about 10 months ago :)

Onur Gümüş said...

@frank silbermann: Wow, that was very infomative about wicket. I admit I've just skimmed over wicket 2 years ago. The main reason I stayed away from it was Java itself. Actually it was Sun who made me detest from Java. Actually from your post, wicket looks componentized as asp.net. I don't understand why would one love one but not the other.

The main problem is we developers, already made our choices about .net or java. I am coming from Java. That's why I feel lucky. "Otherwise I would have been a Visual Studio Monkey"

Onur Gümüş said...

@paul

"The good news is that .net programmers have a great base to build modern frameworks. The bad news is that a lot of programmers with a background in the Microsoft world are reading books about how to write last-gen apps in ASP.NET , drinking the kool aid, and building apps that they, their employers, and the users of the apps will regret -- rather than wishing they were programming some cool like RoR, they should learn from other environments and build a next-generation system that rocks."

Very good sum up!!!

leonardoavs said...

Yo no quise decir que las librerías de Mono para Asp corrieran en Java lo que quise decir es que el código fuente de C# que produce las librerías de Asp.net para Mono es desarrollado por MainSoft la cual tiene un compilador C# que compila a Java ByteCode. Esto quiere decir que después ese código es compilado por el proyecto Mono (con su propia implementación del compilador para C#) para producir MSIL y ensamblados, si yo sé que no se necesita java para correr Asp.net con Mono pero lo que si se es que Asp.net puede correr en Java y trabajarse en Visual Studio gracias a MainSoft prueba de esto es que el WebSphere de IBM corre Asp.net compilado a ByteCode Java. Ósea en cuanto a riquezas y como dice el lema de la Oracle Java es productividad con escogencia no es solo una rama que me dicta que hacer.

Web Development Services said...

I like and appreciate you to provide me immense information. Ethical SEO India techniques always improve site ranking for any websites.

Website development experts give due importance to the content on your website.

Web Development India said...

Excellent read, I just passed this onto a colleague who was doing a little research on this topic.
A well qualified work force that possesses technical skills along with the know-how is a great bonus that India offers to the world.

Website laten maken said...

I recently came accross your blog and have been reading along. I thought I would leave my first comment. I dont know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.

Website laten maken said...

Nice blog. Please keep posting and i'll will keep visiting this blog very often.

Unknown said...

Nice post really the information that you have shared is very good and useful for the web developers, thanks for sharing....

Asp.Net Web design Development said...

Nice info...keepitup
asp.net-development

carney brock said...

Awesome article bro. Very helpful. Thank you very much :).
Web development company in Toronto

Mike said...

Got today the best blog post on the topic of Website development Dubai also got the service even at Cost-effective price.