Ask HN: Angular/Knockout/Ember, logic in templates, and maintenance
I am astonished by the really positive feedback these frameworks are getting lately on HN and other places.
For sure, they tackle a common problem and offer some really sleek solutions but the one thing that really bothers me is their use of HTML and templates:
<a href="#" {{ action "edit" target="parentView" }}>Edit</a>
Or something along those lines.What is really the difference between the previous line of code and this:
<a onclick="doSomething">Click me!</a>
Their use of HTML as something that it is not reminds me of ColdFusion and the really unreadable and unmaintainable HTML it required.So I really have to ask, what happened to separation of concerns and using HTML for markup, CSS for styling, and JavaScript for behavior?
Why is mixing markup and behavior so appealing? Or is it just something you live with in order to benefit from other aspects of these frameworks?
How maintainable is the code you produce using these frameworks?
6 comments
[ 2.9 ms ] story [ 25.9 ms ] threadThe impressive feature of knockout (and angular) is automatic updating of UI when model data changes.
Knockout calls it "viewmodel", that is, the model is not necessarily your data model (though it could be!) but rather it's a model for the view: the state of the viewmodel determines the state of the UI.
Why would you say that this is wrong?
It even has a wikipedia page: http://en.wikipedia.org/wiki/Model_View_ViewModel (not that this matters, but it's a counter argument to "it's not standard").
For example, from Knockout's homepage: http://knockoutjs.com/img/homepage-example.png
That mixing of HTML and JS variables (in data-bind: chosenTicket, tickets) and behavior (click: resetTicket) looks very alien to me. It just doesn't feel right.
It does make automatic UI update very very easy to implement but at what cost? Is code like this maintainable? Is it easily testable? Does is scale well?
From what I can tell (mostly by intuition and experience), this looks at least more maintainable than typical MVC systems like Backbone.js
I wouldn't consider actions in the template to be logic; if the actual event handler were in the template then I'd see a concern.
I like to think about it like a cycle: the template actions are received by the states, which make changes to the models and controllers, which update the views and templates.