Earlier this year I had the opportunity to hear Elliott Sprehn talk about Angular at cfObjective. I found the session fascinating and promised myself I'd play around with it a bit more later. I've finally gotten around to doing so and I thought I'd share a few thoughts on why folks may want to check it out.
First, what is Angular? At a high level it's a JavaScript library, much like jQuery is. (Edit: Ok, so "library" is not how Angular likes to describe itself, as you can read here in the "More Angular Philosophy" section. I get that - but I'm leaving the text in because I think it's the most direct way to get people thinking about Angular.) But what specifically does it feature? I'm going to quote their site and give a bit of commentary.Declarative UI Templates
HTML is already a good templating language; angular makes it better. Preview your UI in your favorite HTML editor.
Right away one of the first things I noticed was that Angular reminded me a lot of Spry. I know I don't use Spry much anymore, but I have a great deal of respect for how easy Spry made it to take Ajax-loaded data and display it on screen. There's work being done on the jQuery side to help that as well (with templates), but seeing Angular's built in support for it really blew me away. As a simple example, and I know this won't be terribly clear out of syntax, but here's a simple template that iterates over a list of phones:
<ul>
<li ng:repeat="phone in phones">
{{phone.name}}
<p>{{phone.snippet}}</p>
</li>
</ul>
Code like this is something that a non-developer could easily work with. You could imagine a designer going in and tweaking layout.
Two-Way Data Binding
With angular, the view and data model are always in sync -- there is no need for manual DOM manipulation
What this means - to me anyway - is that there is much less $("#foo").html() and more just name=something. The binding allows you to work with data and have your display automatically update. It simplifies things quite a bit.
Framework
Angular supports the entire development process, provides structure for your web apps, and works with the best JS libraries.
MVC with Dependency Injection Separation of concerns, loose coupling, and inversion of control -- all the good stuff for testable and maintainable code.
This is where things get interesting. I've done a lot of jQuery work. A lot. But in general it's small features - ie a few things on a page. Certainly useful - powerful - etc. But not necessarily very deep. I've done a few games where I've gotten close to something that's a bit complex, but it's been a bit of a struggle to figure out the best way to organize things. It's a problem. And as I've said before - MVC (and design patterns in general) exist to help solve problems. I'm still wrapping my head around how Angular does this, but from what I see it makes adding MVC to your application very straight forward - especially with it's use of DI.
Here is what really sold me on Angular and - frankly - impressed the hell out of me. Angular has a tutorial. Ok, so do most frameworks. But what really surprised me was how well their tutorial is presented.
First - they make use of Git. Now - if you've never used Git before - don't let that scare you away. They lead you through how to get Git and tell you precisely what command lines you need to use. You don't have to learn Git. As you progress through the tutorial you load in a new branch for each step. What I realized - pretty early on - was that this allowed me to play around a bit. In fact, at the end of each step they have a set of experiments for you to try. This encourages you to screw around and best of us - if you break stuff - you have nothing to lose. Just go ahead to the next step and use Git to set the code up.
Second - they make use of unit testing. Right away. I'm not a TDD extremist, but I definitely encourage the use of unit testing, and seeing them being used throughout the tutorial was great. Let's be honest - no one is testing enough. (It certainly isn't just a problem for ColdFusion devs.) The more encouragement folks have to add testing to their development cycle the better off we will all be.
I haven't yet done any demos with Angular, but I'm hoping to build something involving a ColdFusion back end this week. I'm also interested to see if I can rebuild my old Hangman Adobe AIR application to make use of it. If any of my readers have used it and want to share their experiences, I'd love to hear about it. I'd also recommend the mailing list. I posted there a few times and got responses pretty quickly (and friendly responses at that - friendly communities rock).
p.s. Ok - so one thing I'm not sure about is if I should be calling it "Angular" or "AngularJS" or "<angular/>". I can promise you I'm not going to use the last version - that's too much typing. ;)
Archived Comments
This is one of the reasons why ExtJS is so good, not only is it an OO framework but all the UI widgets are made up of smaller OO snippets of code, that can be easier to extend/overwrite and get that extra functionality. Don't like the way the Grid displays its data, then extand/overwrite the view class for the Grid and you have changed the way it looks, behaves with extremely minimal code.
Templates are no excpetion, ExtJS has had such things as templates before it even hit version 1.0 from memory. But to be able to write something like this has so much power, and so far I have not even seen jQuery come close to matching ExtJS and its awesome in these two areas.
ExtJS has had excellent Databinding for years and now with the new model, has become even more pwerful and it is has been using an MVC type of approach for sometime now, and has gotten a huge overhaul in the latest release as well.
And ExtJS has a similar approach to DI in the new release as well.
Now having said all that, it might still be worth a further look down the track.
Sorry not to ditch Angular, as it looks interesting. It is just that Angular so far is no different to ExtJS or ExtJS core at this stage except that the license may be appealable to many for Angular.
I've never had any doubts about the capabilities of Ext - I just plain don't like it. Much like I'm sure I could use Ruby to build sites like ColdFusion, I don't like Ruby's syntax and wouldn't enjoy coding with it.
Ok Ray why don't you like it?
The syntax is almost identical between ExtJS core and jQuery, and both provide the same desired results towards the end. The only difference is that one can write far less code with ExtJS than jQuery put together.
But as that is now off topic, I am sort of liking the way the binding works in Angular. The problem that I am seeing at the moment, and this may chnage in time as google develop this further, is the time it takes to traverse the DOM to make the binding changes. I haven't looked to far into this as yet, but from what I can tell off the cup, is that it traverses the DOM looking for the binding block and changes it accordingly.
So the more that needs binding on the page, could mean problems with the user experience as well. Might not be the case, but something to be aware off I guess.
Do I have to have a logical reason? I just don't. :) To be fair, some constructs in jQuery bugged me at first too. Maybe I haven't given Ext a fair shake. At the end of the day - it just doesn't interest me I guess.
Binding: I know binding can be an issue in Flex apps. I _seem_ to remember Elliott saying they worked to make binding perform well. I can't say that for certain though.
Knowing Google they will have looked at it with serious intent to overcome the DOM traversal, but in time it will worth keeping an eye on to see how well this develops and/or matures overtime.
Ajax performance in general is still something I don't know how well to test. I've got a good hand on the data portions (lessons I learned painfully), but outside of that, I've got a lot to learn.
Well to be honest I have done none of the tests to answer that either, but from what I can say with most frameworks that use Ajax are still using the standard type wrappers to the browser way of doing it. The difference is that there are extra featurs like callbacks and events that you don't get with the standard browser XHR way, not to mention configuration params for post and get etc, that you would have to write manually yourself.
I think the extra time it takes to run this wrapper for Ajax is nothing to be concerned about either. It will always run faster than the time it takes to connect to the remote call and get what you need. And at that point you are in the hands of your favourite browser.
Ray,
Just a friendly heads up. In the second point you make to support how impressed you were with their tutorial (I was too BTW) you write "I'm now TDD extremist". I think you mean to say "I am not a" or "I'm no".
Since I never got the TDD evangelist vibe from you I am just looking out for your inbox flooding with that type of questions on Monday morning :)
Jean
In my opinion the best JS MVC framework available today is backbonejs. Not really digging these frameworks that want to do data binding through dom elements. Just feels icky to me. Backbone really helps you write better JS, making it clear how to best separate code, but keeping it light on convention. Check it out: http://www.backbonejs.com
@Jean: Oops, yep, I meant "not" - thanks.
@Dave: I've heard good things about Backbone too. I'll try to take a look sometime this summer.
Yeah Backbone is supposed to be fantastic, I haven't used it for nearly 5 years though so its probably gone through a lot in that time too.
@Andrew-- +1 from me for ExtJS. I've not used jQuery enough to really make a comparison, but I've loved working with ExtJS over the last couple years.
Curious: have you done anything with ExtJS 4 yet? I have to say, the full-on MVC approach threw me for a loop at first, but after using it for developing an entire application, I'm sold :)
@Existdissolve: Not sure if your second paragraph was for Andrew or "all of us", but for me, I haven't taken a good look at Ext lately. Maybe this summer - along with Backbone, I'll take another look. I still feel like it won't be a good fit though (and that's not Ext's issue of course).
Yes I have played around with ExtJS4, and can I say I love it. Was a pain to migrate some badly written code, but its worth the upgrade.
I also made a blog that shows how to read in an XML file into a data model, that can be used for a lot of scenarios. Data Models rock, the fact that they now support relationships, of manytoone etc, absolutely rocks.
http://www.andyscott.id.au/...
@Ray Thanks for kinds words. Feel free to drop us an email on the mailing list if you have any further questions.
@Andrew don't worry about the data binding performance. It might surprise you to hear, that it performs better than a hand-coded dom manipulation in most cases. Especially if you start using repeaters (ng:repeat).
I gave a lightning talk on this topic at Velocity conference recently. It might be worth it capturing the main points in a blog post. In the meantime, you'll have to take my word for it or benchmark stuff for yourself.
@Igor, is that with a deeply nested dom?
From what I have seen so far, still want to find some time to sit down and play with it myself, but it looks fairly good to date.
Just note about ExtJs (I'm talking about v3.4, haven't touch v4.0):
I think ExtJs is FANTASTIC, especially the UI components. The overall design of the framework is good from the extendability point of view, but unfortunately not for testing. The separation of presentation and logic is very bad.
I worked on one bigger project on ExtJs and this was a big issue. It took a lot of energy to test and organize ExtJs code.
So this is a big advantage for angular - clear separation of logic (with full unit/e2e testing environment) and declarative presentation.
@Andrew we traverse the dom only once - when the application starts - we call this phase html compilation.
Once a template is compiled, we have all the references to DOM nodes that may need an update, as well as all the binding expressions that we need to use to watch the model for changes.
So if anything, it might be the number of bindings on a page that could slow down your app. We estimate that you'll start to see issues only after adding a few thousand bindings to your template, which nobody has had a need to do yet in the real world.
@Igor, sorry but that was what I was referring to in the first place. I know even with the likes of ExtJS, jQuery and others the more DOM Nodes there are on the page, the slower it is to move something around on the screen. I used that as a reference, beause I would have imagined that the more binding on the page would have some impact.
Now this is not the fault of the JS framework/library as we all know, most browsers handle there DOM differently when they traverse etc.
So yeah that was my main concern, whether that might still be a problem.
Still I think so far this is still worth much further playing around with.
@Voita that I couldn't argue with, however in ExtJS4.0 it is now taken a leaf from Sencha Touch which is to now have an MVC type approach.
I am not sure it is perfect, haven't really had a good play with it as yet. But it looks fairly impressive to say the least.
@Andrew we have yet to see a real world (useful) app, that has performance problems that we can't address somehow.
@igor, cool it was only a thought anyway.