Lately I have been speaking quite a bit about building Single Page Applications. Most recently I have been arguing that we skipped the discussion of weather or not we need a framework at all to build a Single Page Applications? Everyone quickly got into the battle of the frameworks, and argued about the good and bad parts of Angular, Ember, Durandal and a bunch of other contenders to the throne. These days I would argue that Angular won, which is supported by google batteling the frameworks, looking at training courses offered and joblistings. As a .NET developer this is furtner obvious now that AngularJS is part of the ASP.NET package, and samples are showing up that use it for Apache Cordova applications, which are also being embraced by Microsoft.
However, the more I have been working with these frameworks, the more I have started to question their actual value. At least to a point where I think it is something we need to think more about, when choosing which way to go. Sure frameworks give you a nice package that tackles application structure, routing, templating, two-way binding and dataaccess - but at what price? Using a framework, always means letting someone else decide a lot of things on your behalf, and it means taking a dependency on a large codebase. So in this blogpost, I will try and make the case for growing your own architecture.
You might think "so what, we do that all the time, we shoulden't be reinventing the wheel and what does it matter to depend on a framework". If they provide enough value I would surely agree, but it should always be measured against the risks of vendor lockin, issues with breaking changes, performance implications and restrictions on growing your application going forward. With a fast evolving web, these issues are very real. A framework might still be a good choice, but we need to at least think about the pros and cons.
Two-way binding is a huge sinner when it comes to performance and modelling restrictions, if the model chosen is not right for what you are building. Breaking changes are hurting developers daily, and with both Angular and Durandal looking to be complete rewrites for their next versions - so if you use them, you will be stuck with the current version, or you will be doing a rewrite of your own fairly soon.
"But we need a framework to build a modern Single Page Application", right?
The frameworks tend to claim that they solve hard problems, but are they really? Templating, routing and data access through REST services are quite basic things by now, and there are pleantly of libraries to help you out, which are easy to combine, and easy to switch out when something better comes along. Two-way binding is often overused to be honest, but when it is needed it is easy to do using native HTML5 API's. So we are down to providing structure, where a generic solution is pretty much never as good as one designed for the actual problem being solved. The revealing module pattern, is likely a good place to start, combined with a mindset of making small reusable parts. Maybe you will end up building your own libraries, that you can then share and make the world a better place?
Other ways of going up an abstraction
In the end a framework may still be appealing, but I hope you will at least give it an extra thought, and make sure you are not just being lured by a new shiny object.