The Right Way To Build Web Apps

A recent thread on Code Project about Silverlight being dead caused somewhat of a heated debate on how and when web applications can replace desktop (or Silverlight in this case) applications.

My answer, in short, was yes, they can, as it always is when this topic comes up (quite often, in case you’re wondering). There are a number of counter-arguments you can think of, but the truth is that you can really build complex applications with HTML, CSS and JavaScript. And it’s even very simple and streamlined. HTML and CSS enable a level of flexibility that no desktop-like UI framework has ever seen in the history of GUIs. If you add JavaScript and a framework of your choice to the mix, you really have an unprecedented freedom on what you can achieve.

To a big surprise, a reader then sent me an email. To cut a long story short, he asked if there are books that teach you how to build web applications.

Like any good developer, I learned most of what I know by doing things and, most importantly, by following experienced fellows via blogs and websites like Code Project. The reader took the time to explain his history, that is mostly in desktop and embedded programming, based on a variety of languages and frameworks. Jeez, he started programming when I was 3. How can’t he find his way through web development? I immediately thought there must be something that’s blocking his view.

I thought about it over the weekend and I figured it’s all about the approach.

The main point in building web applications is to start thinking the right way. You know, ASP.NET WebForms have actually done more harm than good in this respect. The model they promote is completely, deeply and hopelessly wrong. You can’t program a web application as if it was a fucking desktop application. You’re building a skyscraper with shaky foundation, while also hiding your head in the sand and pretending everything’s fine.

I used to love WebForms. I’ve started doing web development with ASP.NET 1.1. It was amazingly similar to WinForms. And amazingly wrong, as I’ve learned later in my life.

We developers are lazy, most of the time. That’s why shiny frameworks that promise to automate boring stuff get great levels of attention. ASP.NET was nothing different. It was an amazing framework that promised to make web development easy even for developers who never did it before. And you know what? It actually worked very well. It delivered on that promise. So instead of finding the right tool for the job (web development), we actually bent ourselves to fit into ASP.NET. And before you start arguing, all of you Microsoft haters, this happens all the time to everyone. 99.9% of developers fit into the tools they have at hand and which are often imposed by upper management levels. The remaining 0.1% find themselves in the position to create a new framework because they actually figured out that existing ones are crap. Example: Ruby on Rails. But creating a new web framework is not like flipping a hamburger. It’s not for everyone. Unless you’re 37signals, you’ll have a hard time coming up with something decent, and even if you’re 37signals you’ll get lots of things wrong.

So it was late 2009 and I’ve been using ASP.NET for like 3 years. I had built a large web automotive web application, plus ScrewTurn Wiki, so I could call myself a web developer (or so I thought at least). For reasons that are not important for this writing, I had to bang out some code (which later became Amanuens) in the shortest time possible. For reasons I don’t remember (probably I wanted to experiment with something new), I decided to use ASP.NET MVC.

BOOM! All hell broke loose.

After a few hours of complete disorientation, I started to understand why WebForms was completely wrong. And before everyone of you starts saying I told you so, let me explain.

Imagine that it’s 2006 and you’re good with C#. You have to build a web application. Microsoft has ASP.NET. What would you do? Without even thinking once, you open Visual Studio and start writing code in ASP.NET. It was natural, and actually made sense from a business perspective. It was a good solution for the problem at hand, and let you feel at home when writing event handlers for button clicks. Event handlers! Can you imagine that? It was like free beer!

But of course it all came at a price. Firstly, you had this huge __VIEWSTATE thing. You had tons of auto-generated HTML that would make web designers tear their eyes off and run away screaming. And you still didn’t have 100% browser compatibility. All in all, it was a limited success from a technical point of view. But you were happy, because it was easy.

Over the months and years, your brain started to bend, to distort reality, and in the end you actually believed that there was nothing wrong with ASP.NET. It was perfect.

Then suddenly brave souls like Phil Haack, Scott Hanselman and their entourage started advocating this new MVC thing. Well, it was huge. It was a completely new world. It was finally The Right Way to do web development on the Microsoft stack. It took me no more than one hour to wake up from the WebForms dream – or was it a nightmare? – and fully embrace MVC.

Why?

Because – and this is the most important thing in web development – MVC does not try to hide HTTP, HTML, CSS and JavaScript under several layers of abstractions and pretend they don’t exists. MVC embraces the models that make web applications possible, treating them like first-class citizens. Sure, ASP.NET MVC still has lots of abstractions, but they’re all good lightweight abstractions. A MVC applications screams The web is not the desktop! with every controller, action and view you write.

So, to answer the reader’s question, surely there are books about developing web applications, but first you really have to understand how the web works and most importantly that it’s stateless, start from there, and absolutely avoid trying to fit the web in a desktop development model. Then probably any ASP.NET MVC or Ruby on Rails book is more than enough.


Posted

in

by