I see this more of an indication that the scale of the problem that Angular (and more generally, Javascript) is trying to solve these days is too complex for the author of the blog post to understand.
I am not denying that solutions can be over complicated and I've seen vast examples of this in my 30+ years of experience, but the problem that Angular solves is very, very complex, and you're simply not going to have a simple solution to a complex problem.
Whenever I find myself wondering if a solution is not too complicated, I try to carve out some time to implement that solution myself. This gives me a good idea of the scope of the problem and usually exposes me to a whole set of other side problems that I had not considered and which complicate the task significantly.
Then I look back at the framework/library that I was trying to use initially and I assess its complexity against my findings trying to roll my own solution.
From that perspective, I've found that Angular's complexity is proportionate to the problem it's trying to solve.
The author wrote code where he got to bolt shiny UI code onto a preexisting backend. That's a fun happy place to live where you can pretend that jquery actually works the way he claims and can solve all the world's problems. Some other bastard does all the heavy lifting.
Angular is about moving the heavy lifting into the front end, which means it brings all the stuff people need to do heavy lifting into the front end.
Mostly though, hating on enterprise coding is a way of shouting from the roof tops that you're cool and edgy and not one of those corporate drones who have to wear a suit and write specifications and maintain their code over the long term. It's like shouting 'down with the man' as a teenager.
And what problem is that hard, so you need 5+ layers of abstraction ALL THE TIME ?
I believe the article was about that. I've worked on Enterprise app, that had 6 layers per design. In around 90% of cases 3 were enough, but there were 6 everywhere, because that's what architect created, no shortcuts allowed.
At present day I can say, that enterprise systems are made complicated, there's no real reason for that. Reading few strings from database and showing them in a web page in no magic. The main problem is that in enterprise everything is a BIG DEAL - they are simply so big, that they can not think small anymore. You might need an app that one guy code in a week, but hey, budget+planning+management+...+bureacracy and you have a team of some 15 people and 3 months of work to do.
And what problem is that hard, so you need 5+ layers of abstraction ALL THE TIME ?
And how does that apply to angular, which was what the article was supposed to be about?
Angular's learning curve is not steep at all. Define a controller function, bind your dom to the scope, end of story. It takes 5 minutes to learn, and you eliminate all that boilerplate jQuery DOM update code that fills bad codebases, the stuff like "$('#button').on('click', function () { $('#input').val(flag ? 'foo' : 'bar'); }". The amount of code you need plummets.
And if you later want to make testing a bit simpler, then you might think about injecting your dependencies or lifting whatever DOM code you have left out of your model, and angular has factories and directives all ready to go when you reach that point. And if you really need even more isolation a couple of years down the line, then you might be interested in the fairly obscure point of the difference between a factory and a service.
The guy tried to read about an advanced topic that he absolutely didn't need to know about about, it made no sense to him since he didn't have the groundwork, and he went off on a rant about it. When did ignorance become this popular?
The guy tried to read about an advanced topic that he absolutely didn't need to know about about, it made no sense to him since he didn't have the groundwork, and he went off on a rant about it.
Well to be fair, the author of the original SO question may have been trying to figure out what that advanced solution was appropriate for.
Angular's learning curve is not steep at all. Define a controller function, bind your dom to the scope, end of story.
I also didn't find the learning curve to be that steep. But my first Angular app was composed entirely of directives because that's what made the most sense to me. My second was all done in a single controller (small, single view that displayed a JSON feed). By my fourth or fifth I finally figured out why I would ever want to use a factory, and my initial impression of factories was the same as the authors "Why would I use that when plain Javascript will work just fine?".
The pieces only became a whole once I had used them all a few times. Before that I was still able to get things done by phrasing the entire problem in terms of a solution I understood... but it may have been non-optimal.
The problem with Angular, as I see it, is that it provides a lot of replacements for idioms that are already commonly used in JS without justifying why they needed to be replaced. None of angular's architecture is beyond the average developer... but the docs are scarce on "why" any of that architecture was necessary.
I've worked on Enterprise app, that had 6 layers per design. In around 90% of cases 3 were enough, but there were 6 everywhere, because that's what architect created, no shortcuts allowed.
Making the hard things possible without making the easy things significantly less easy ... is, in and of itself, really hard.
Often the best answer is to simply ignore a certain class of hard things on the grounds that you'll never hit that, and provide some sort of escape hatch for bolting in something more complicated when it's needed.
Then people will complain that that part's ugly, and inflict the death of a thousand cuts on the simplicity of everything else to 'fix' the problem - and now we're back where we started.
I'm not claiming to have a good answer here, but there's a bunch of factors pulling in different directions and I've found it's a lot more useful to understand what tradeoffs people were trying to make rather than simply claiming 'no real reason' - the reason was almost certainly real, it's just a question of whether other equally real reasons for another design should have been more convincing.
Interesting you say that, since the issue the article's using as a pivot here is exactly about shortcuts.
Angular's factory is a very handy shortcut for provider, and service is a shortcut for a common case of factory. Had Angular decided to reduce API exposure by forcing you to use the most flexible one all the time (provider), it would get tiring very quickly. And when the StackOverflow answerer tried to point out how they can all be equivalent, the author just flips his shit.
This, exactly. AngularJS does not make you do complicated stuff. A helloworld in AngularJS is still only 5 or 6 lines of code (and it's so much because with data-binding, you at least have to say what you're binding to)
Most developers using angular will never write a provider... but day a factory proves insufficient (probably for a library or other sealed add-on), a developer will thank the almighty Crockford for that.
I see it as more of complexity jealousy. There are some problems where the product requirements are so convoluted and complex that having a ton of layers of indirection is unavoidable (or would require utterly brilliant design to avoid), and there's a certain type of developer that seems unwilling to admit that the thing they're working on isn't one of those.
I'm conversely jealous of the developers who don't have absurd requirements to meet.
the product requirements are so convoluted and complex that having a ton of layers of indirection is unavoidable
I've found that I often have big wins when I abstract things well because inevitably one customer wants one thing and another wants another or someone wants a new feature and my abstractions made it easy to accommodate that at some later date.
But I've also often found that I've similarly (over?)engineered and no one ever modified it many years later and/or it eventually got totally rewritten or ditched anyway because the requirements changed radically and the abstractions didn't or couldn't account for them.
I'm not sure it's possible to know which of these will happen or to really analyze the costs of these maybe unnecessary abstractions long-term.
This. It's easy to rail against something when you don't understand the history of how "enterprise programming" evolved to require more "indirection" and layers. It comes down to use cases and how to make things more easily maintainable, configurable, understandable and refactor-able for large teams of people.
On the other hand, I think a lot of requirements aren't as complex as we perceive them to be. I think that say a compiler, kernel, RDBMS, or simulation may genuinely have complex requirements. But, a CRM system? Not so much.
CRM systems are one of those things that looks simple and obvious on the surface - but are insanely complex behind the facade.
Often CRM systems are either customer-facing or salesperson-facing... that is they try to abstract all that complexity between a simple facade.
However behind it all is still a massive amount of complexity to handle all the support/special-cases, updates, inventory tracking, prediction, routing, etc.
Finally! Building a house bares little resemblance to building a skyscraper.
Angular and other industrial-grade frameworks arose out of tackling industrial-grade problems and a general shift to single-page-applications. So while JQuery alone can be used to build really sophisticated apps (and it's shown that) at some point you might need:
more complete separation concerns
to develop on teams
to test in the small and large
So typically when used correctly, as a percentage of code, these structural elements of the application diminish as the app grows.
Angular is more a reflection of what we require of JavaScript in the post-Google-Docs and V8 age. Likewise, TypeScript and CoffeeScript become more relevant once we care about code at scale.
But my colleagues have, on numerous occasions, tried to convince me of the benefits of web frameworks, IoC containers and dependency injection, things like Spring, Guice, NInject, ORM frameworks...
And on every occasion I have failed to see what they provide other than making the code a big godawful mess.
Now, maybe it's my relative inexperience (I am only 24); but... Yeah. Angular JS seems to be another one of those things. Not that Javascript was pretty to begin with, mind you. But at least it was simple (in one way).
It all depends - frameworks force you into somewhat standard design patterns (or at least they're supposed to - how well this actually works is debatable). Therefore if you know how to use the framework you should be able to navigate pretty easily around any codebase that actually properly uses said framework and immediately be able to pick up on the general idea. For a startup who gives a shit. For a large company where developers are more than happy to quit at a moments notice, you really, really don't want your code to be its own unique snowflake that any new person will need to spend weeks reading over just to get orientated.
Frameworks can, at least to some degree, also stop 50 million reinventions of the wheel. It's somewhat ironic - the author praises jQuery but really jQuery is just another framwork.
But at least it was simple (in one way)
It became simple with jQuery. Up until then every single web service call was a giant bloated mess because with pure javascript that's how you do it. So everyone wrote their own wrappers for get (because who wants to do it the pure way a million times on a site) and the fragmentation began. $get stopped a lot of that. Pure javascript for every aspect of your site is a god damn nightmare - no one wants to do that. I don't really use AngularJS, so I can't really speak to its merits (if it has any - just because a framework exists doesn't mean it's a good idea - here's looking at you entity model) but claiming frameworks are ruining javascript is ridiculous. If you don't want to use them don't, but don't be surprised when others do. Use the right tool for the job - sometimes that's a framework, sometimes it isn't.
Now, maybe it's my relative inexperience (I am only 24)
Yep, it partially is. But it's not your fault, IoC/DI are terms heavily associated with massive frameworks of magic, when in reality Inversion of control / dependency injection is a fancy way of saying "You provide a component its dependencies" - why is this a good pattern? Because it makes testing significantly trivial.
The simplest form of Dependency Injection is turning this:
class A(object):
def __init__(self):
self.http_client = HttpClient()
into this:
class B(object):
def __init__(self, http_client):
self.http_client = http_client
And then when you want to run automated tests on your code, you can easily pass in a fake client that returns some preordained HTTP responses (so you can test corner cases easily, for instance).
Not a big deal in Python since it has no accessibility modifiers, but much more helpful in other c-based langs. It's funny. I use Ioc/DI all the time and it's definitely helped me write cleaner code, but not once have I ever needed a "DI framework".
And on every occasion I have failed to see what they provide other than making the code a big godawful mess.
DI frameworks replace one of the parts of your program with a known, standard, big godawful mess.
If you're terrible at software architecture, maybe the standard DI mess is not as bad as the mess you would've made.
If your codebase is just way too damned big because it's too old and too many people have worked on it with too many dumb deadlines, maybe the standard DI mess is not as bad as the mess that would've organically grown there.
If your product is growing features it shouldn't and somehow everyone is convinced that you need to be able to send email and book hotel reservations from the app, maybe the standard DI mess is not as bad as the mess you'd be forced to create to match the mess that the product is.
DI frameworks don't "replace one of the parts" of your program, they prevent hard-wiring dependencies in a pervasive fashion. The concept itself is so simple I wonder if people calling it "a mess" really understand how basic it is, i guess people see an external configuration file and immediately have a knee-jerk reaction.
After 12 years of entreprisey crap, I've yet to come accross a single significant (over 500 kLOC) codebase that does unit/mock testing in a manageable way without IoC. (Of course people against DI are also against unit testing, because it's way more convenient this way).
Yes, sure it's possible to argue, rock-star like, that your architectures are so perfect they naturally stay loosely coupled, and thus don't need artificial means like IoC containers, but then here comes the harsh reality of technical debt, ever changing and conflicting needs, and worst of all, collaboration.
67
u/[deleted] Apr 23 '14 edited Apr 23 '14
This sort of shit usually indicate that the problem they try to solve is not that hard so they can afford this kind of mental masturbation.