3 ms·
> It's about imperative vs declarative styles in DOM modification, animations, etc. I don't understand. I mean, Angular doesn't seem any more "declarative" tha
by ssmoot 13y ago
> It's about imperative vs declarative styles in DOM modification, animations, etc.
I don't understand. I mean, Angular doesn't seem any more "declarative" than the Behavior.js you could write 7 or 8 years ago.
And jQuery made setup a bit different, but you could easily still keep doing the same thing with declarative decoration.
When talking about directives (specifically) Angular doesn't appear (to me) to really offer anything new outside of some questionable conventions for structure.
- bmm6o 13y agoAngular is an MVC framework, which means that your code should be updating the model and letting Angular push that to the view. A lot of the stuff you would do with jQuery is directly updating the view. So instead of writing something like: $('#whatever').addClass('selected'); // say this is in an event handler you should write: $scope.isSelected = true; // this is your ng event handler and the html is like this <div ng-class="{selected: isSelected}"> That is, you think a lot more about the model and how it's represented in the view (declarative) and less about what to do to the view to make it look the way you want (imperative). That's not to say that there's no place for jQuery in an angular app, but it does replace a lot of the typical uses. And fighting it just leads to frustration.
- ssmoot 13y agoI guess it's a grey area, but that all looks pretty imperative to me. I think a Calendar Directive is probably a better example. But the declarative part (ng-calendar vs a jQuery binding for data-calendar) is the smallest part of the effort. I don't know... it all just feels like a lot of work for little benefit. Back in the Rails 0.x to 1.x days even point releases routinely broke applications. In hindsight it was a terrible idea to build on the platform at that time. Going with more mature solutions would ultimately be more cost effective for anything but prototype level demonstrations (IME). Angular feels a lot like that. Plus the whole nested controllers are pretty reminiscent of Windows Forms programming. Which was an awful paradigm that was replaced with stuff much closer to HTML for a reason. So Angular feels like repeating the mistakes of the past. On top of that you're using a fairly terrible language, and reintroducing the idea that you need to write tests to prove syntax and correctness at a text level. Then you write more code to accomplish less. And 6 months on you've spent more money than the team who went with HTML and jQuery, and over the long term you've increased maintenance costs over that team's output if they've put any care at all into maintainability, encapsulation, modularization, etc. That's just my personal experience anyways. It's an awful, terrible, complex, fragile framework with a lot of busy-work attached in a runtime that's just not very good with these patterns. I mean Patterns are Typed. That's the unspoken bit. You can't describe an ActiveRecord, a DataMapper, MVC, MVP, Strategy, etc without Types. And JS has about the weakest Type system among mainstream languages I can think of. I implemented a "JavaScript on Rails" sort of system in JScript in ASP Classic some 8 or so years ago. The fact that the runtime is persistent now and parsers much faster doesn't much change the fact that it's still an awful idea IME leading to... well, a lot of wasted time and money when you could instead be doing something predictable, that's more maintainable, runs faster, and is less expensive to develop and maintain. But maybe that's just me. :)
- bmm6o 13y agoSure, I wish Javascript had a stronger type system too, but I'm not sure how that's relevant to an Angular/jQuery discussion. You still have business logic that you either test or don't test, right? At least angular globally supports DI for sane unit testing. You're right that directives are very declarative, but I didn't mention them because they don't really have a counterpart in jQuery unless you rolled your own. I like Angular a lot. Even just the data binding and $watch system would relieve a lot of tedious code and can make for a really responsive UI.
- ssmoot 13y agoThe relevance (to my mind) is that Angular tries to bring in MVC and other Patterns. And I think any time you attempt to mix PoEAA style Patterns with weak Type systems you're trying to force a square peg into a round hole. IME it's much more successful to focus on the Functional aspects, Declarative binding, and Modularization since with tools like jQuery these things are JavaScript's bag. And Angular is about as far from a Functional style as you can get. So to me at least it feels very much like the wrong tool (JavaScript) for the job (building and using an MVC framework).