TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

AngularJS: The Bad Parts

226 点作者 lars超过 10 年前

26 条评论

serve_yay超过 10 年前
Actually, I think an opportunity was missed in the section about dependency injection. The problem of minifying is easy enough to avoid - you just don&#x27;t use that form. (I do agree that the tutorials shouldn&#x27;t be teaching the dangerous form, and the dangerous form shouldn&#x27;t even be a thing.)<p>No, what I hate about Angular&#x27;s DI is that it tries to make inferences about the name you give it, instead of the name being an unambiguous identifier. It does this for &quot;convenience&quot; but it just ends up causing problems and making incorrect guesses.<p>I&#x27;m talking about how, for example, if you have a class called WobbleController, you don&#x27;t inject &#x27;WobbleController&#x27;, you inject &#x27;Wobble&#x27; and Angular just &quot;figures out&quot; the &#x27;Controller&#x27; part. Pretty sweet when it works! Wow, you don&#x27;t have to type 10 characters! (Good luck grepping for it later, though.)<p>But when it makes a wrong guess it seems impossible to fix. The other thing that sucks about this is that you have to reload your app to see if Angular will actually be able to find the thing you&#x27;re injecting. This whole thing is supposed to save time, and it just doesn&#x27;t. It sucks.
评论 #8563717 未加载
评论 #8564306 未加载
nyir超过 10 年前
The article didn&#x27;t mention my favourite (ha) pet peeve with Angular, error handling, which makes me wonder about if everyone else doesn&#x27;t have that problem: even after working with the framework for a couple of months now, I still run, about every other week, into the issue that if something doesn&#x27;t work, there is exactly zero indication of that. Most prominently misspelled names and parameters of directives. You&#x27;re lucky if you get an error in the Javascript console, if you happen to have that open all the time.<p>To me that&#x27;s infuriating. I get that Javascript isn&#x27;t Haskell (and I don&#x27;t even want to go that far into that direction), but the combination of extreme leniency and the remarkable absence of checks is really bad.
评论 #8564384 未加载
评论 #8564150 未加载
评论 #8564107 未加载
saosebastiao超过 10 年前
I&#x27;m pretty new to front end development, and a few months ago I started learning Javascript by experimenting with a few front end frameworks. When I got to Angular, I dropped it the moment I saw string-based expressions. How is that even remotely acceptable? I can&#x27;t even imagine the bugs I would be embedding everywhere.
评论 #8563417 未加载
评论 #8563540 未加载
评论 #8563336 未加载
评论 #8563364 未加载
lobster_johnson超过 10 年前
Coincidentally, the scoping issue is almost exactly the same issue that plagued Zope, a Python-based app server, back in the day.<p>In Zope, any property could be inherited not just from the parent object, but from the current context; you could invoke the object path &quot;a.b&quot; and b would inherit from b, but if you invoked the object path &quot;a.c.b&quot;, b would inherit from c instead. They called this design pattern &quot;acquisition&quot;, and seemed rather proud of it until they realized it was the kind of magic that was ultimately too magical for its own good.<p>The Zope guys tried very hard to eradicate it, and in the process ended up alienating all the developers with the new, non-backwards-compatible version. Funnily enough, there is another Angular parallel to Zope: Just like Zope 3, AngularJS 2.0 is also not backwards-compatible.<p>Angular&#x27;s parameter-based dependency injection is coincidentally the same reason Martini [1] is slower than most other Golang web frameworks. Clever, sure, but ultimately a design flaw.<p>These problems demonstrate how important it is to introduce a good design from the very beginning. You can fix bad code, but bad design is much harder to change.<p>[1] <a href="https://github.com/go-martini/martini#service-injection" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;go-martini&#x2F;martini#service-injection</a>
评论 #8568438 未加载
moogleii超过 10 年前
Our team chose to use angular admittedly because of its popularity (it&#x27;s also why we chose bootstrap over foundation, though that probably had smaller repercussions). Most of the rest of the team then ran off to work on other stuff, so I ended up with most of the angular work. It&#x27;s been at least 8 months now, and I&#x27;ve gotta say the article is pretty spot on.<p>But I don&#x27;t really mind anymore for two reasons: I know most of the gotchas now (probably after some loss&#x2F;whitening of hair), and I haven&#x27;t used any of the other major frameworks (like ember) to really be able to make an informed comparison.<p>I don&#x27;t know if there&#x27;s a real takeaway here. Maybe &quot;evaluate major contenders even if one is super popular&quot; or &quot;be more vocal when someone tries to blindly railroad in a candidate&quot;?
评论 #8563816 未加载
nawitus超过 10 年前
Just today I lost half an hour figuring out why my ng-show worked for all other strings except for &quot;f&quot; and &quot;F&quot;. AngularJS definitely has it&#x27;s own traps..
评论 #8563802 未加载
评论 #8564238 未加载
likeclockwork超过 10 年前
There is so much in this article that is disingenuous.<p>For example point #4 complains that Angular redefines Constructor to mean something else.<p>The controller constructor IS a constructor, it constructs an instance of a controller and can request and decorate(or construct) a new scope by injecting $scope.<p>But the debate aside... the quoted revision is over a year old! (It also hasn&#x27;t reflected the behaviour of the controller constructor for even longer than that, but that&#x27;s a separate matter.)
nogridbag超过 10 年前
When I was evaluating Angular, the near deal breaker for me was that the router could only swap a single view area - which is useless for anything more than a trivial &quot;Hello World&quot; example. To build a real app, I would have to divide it into multiple small Angular apps. Is this still the case with core Angular?<p>I realize there&#x27;s the third party AngularUI UI Router project. I&#x27;m assuming everyone who uses Angular for any real project uses that.
评论 #8566011 未加载
grannyg00se超过 10 年前
The scoping should be made more explicitly against a particular controller.<p>The issue is resolved simply by using controller as syntax which is recommended in many blogs. Point taken about the pit of dispair though.<p><a href="http://jsfiddle.net/sndyxfdk/1/" rel="nofollow">http:&#x2F;&#x2F;jsfiddle.net&#x2F;sndyxfdk&#x2F;1&#x2F;</a>
EugeneOZ超过 10 年前
that&#x27;s why 2.0 is complete rewrite - exactly to eliminate all these bad parts.
评论 #8563638 未加载
评论 #8562932 未加载
评论 #8563735 未加载
评论 #8564049 未加载
mcv超过 10 年前
I loved Angular. And I still love many parts of it. I like the declarative style, the automatic data binding, and all that other stuff that&#x27;s painful in JQuery, but fairly painless in Angular.<p>Well, painless at first. Because eventually you run into the limitations. The data binding doesn&#x27;t scale, a lot of things that are easy to declare (particularly scope variables for directives) are a lot more complex than they initially seem. The article hasn&#x27;t even scratched the surface on problems with scope in Angular.<p>And then there&#x27;s the fact that my templates keep turning everything into strings. Too often, when binding stuff from an outside controller to the isolate scope of a directive, I keep having explicitly to turn all the strings back into numbers.<p>Still, Angular does a lot of very neat stuff. There are just too many common use cases that the neat stuff doesn&#x27;t really cover very well.
btown超过 10 年前
A lot of people complain about Angular&#x27;s digest cycle and hold up React as the way forward. My understanding, and I could be wrong, is that both frameworks do work for every &quot;binding&quot; to the data in every update cycle - for React, you need to create short-lived objects for a component and its children AND evaluate every dependency on external objects, whereas for Angular it&#x27;s a few function wrappers and iterations on top of evaluating every dependency on external objects. Seems like modern JS JITs should optimize both of these cases so it&#x27;s just the evaluations. And both frameworks have facilities for limiting the scope at which the update cycle needs to run. Am I wrong in saying, then, that React isn&#x27;t inherently more performant?
评论 #8565812 未加载
iamleppert超过 10 年前
Angular is awful. I took one look at the docs way back when we were evaluating at BigCo and walked away.
dscrd超过 10 年前
&gt; Whatever the reason is for Angulars popularity, it isn’t that it’s a great framework.<p>Something similar to this seems to be true for every piece of programming technology that is popular. How did it come to this? Other professions don&#x27;t go in masses towards the worst solutions, do they?
评论 #8564592 未加载
评论 #8564673 未加载
评论 #8564815 未加载
serve_yay超过 10 年前
I&#x27;ve built a couple things with it, and I wouldn&#x27;t use it again. But it&#x27;s very popular!
bsaul超过 10 年前
i&#x27;ve written a fairly large angular app, and the ng-if case struck me as totally incomprehensible (why the hell would ng-if have its own scope ?). Then i realized i&#x27;ve never had to use ng-if.<p>That&#x27;s not to minimize the trouble you get when you first have to learn about scope inheritance, but I think ng-if may be the only completely non-intuitive directive of the framework. (As opposed to something like let&#x27;s say ng-repeat, where you sort of get the intuition that some care will be needed).
评论 #8564661 未加载
leeber超过 10 年前
Here&#x27;s why I like angular...<p>It only took me a couple days of fooling around with it before I built something useful with it. The steep learning curve is only if you want to know the how-and-why behind every feature of the framework (which I still am not even close to). Learning 100% of the framework is simply not necessary for certain apps.<p>It&#x27;s easy in my opinion, it&#x27;s quick, and it gets the job done. If I run into any problems, there about a bazillion stack overflow post addressing my issue already.
评论 #8572052 未加载
评论 #8566604 未加载
评论 #8563962 未加载
hcho超过 10 年前
The dependency injection thing is really a non issue. Just use something like ng-min before you minify and you are set. Just for the price of another entry in your grunt.js file.
评论 #8563186 未加载
评论 #8563075 未加载
评论 #8563054 未加载
评论 #8563431 未加载
msoad超过 10 年前
I understand most of it, but digest loop is a great idea! It&#x27;s much better than manual `model.on(&#x27;change&#x27;, view.render)` of backbone for example. Developer might forget to do this manual rendering for certain actions which is bad
评论 #8563661 未加载
评论 #8563570 未加载
psp超过 10 年前
I think digest loop is one of the best parts of AngularJS. I wonder how it ended on this hate list. I dont think I will agree with much of the rest either.
评论 #8563413 未加载
xfalcox超过 10 年前
I can&#x27;t get the script who counts the bindings to run. Any help?<p>Uncaught TypeError: Cannot read property &#x27;$$nextSibling&#x27; of undefined
评论 #8562921 未加载
评论 #8563065 未加载
pgsuckz超过 10 年前
TL;DR: AngularJS is a horrible framework because it can be abused by newbies and is too &quot;complicated&quot; plus some other non-issues.
评论 #8564961 未加载
kuni-toko-tachi超过 10 年前
Glad the truth is coming out! This will save a lot of developer time and will make SPA&#x27;s even better.
jmstout超过 10 年前
I first tried to view this article on my mobile device and saw this: <a href="https://dl.dropboxusercontent.com/u/117695213/static/larseidnes.jpg" rel="nofollow">https:&#x2F;&#x2F;dl.dropboxusercontent.com&#x2F;u&#x2F;117695213&#x2F;static&#x2F;larseid...</a><p>To me, this is already revealing. A critique of a web framework and this is the first impression I get? Not off to a good start. There’s a reason people find it hard to trust a fat nutritionist. I see parallels here.<p>Lately there has been a lot of negative feedback about AngularJS and I have been interested in the critiques of its shortcomings. For this reason, I gave him the benefit of the doubt, pulled up the article on my computer, and dug in.<p>His initial complaint about prototypically inherited scope properties (Bad Idea #1) being confusing and &quot;literally impossible&quot; to predict was perplexing to me. He states that he understands a child scope will inherit from its parent scope, yet doesn&#x27;t explicitly instantiate any object on the parent controller in his example of the so-called problem ( <a href="http://jsfiddle.net/1op3L9yo/" rel="nofollow">http:&#x2F;&#x2F;jsfiddle.net&#x2F;1op3L9yo&#x2F;</a> ). A child of a parent with no properties inherits nothing from its parent -- this seems obvious. If properties are actually defined on the parent the child will inherit them. Is this not the expected behavior?<p>The &quot;fix&quot; for his &quot;impossible&quot; scenario, is to make sure you explicitly define the property on the parent.<p>In his specific example, that would look like this:<p>$scope.obj = { prop: &#x27;&#x27; };<p>( <a href="http://jsfiddle.net/355fuxk5/" rel="nofollow">http:&#x2F;&#x2F;jsfiddle.net&#x2F;355fuxk5&#x2F;</a> )<p>He complains: &quot;Whether or not a new scope is introduced by a directive is up to its implementer. And if a new scope is introduced, it is up to its implementer to decide if it inherits from its parent scope or not.&quot;<p>How is this a bad idea? I like choices in life, don&#x27;t you?<p>He talks about dynamic scoping being a terrible thing. I think the alternative, dictating One True Way of doing things, removes flexibility. This would be far worse than the current status quo of leaving it up to the developer. He advocates for removing this choice altogether, but is there NEVER a good use case for this &quot;dynamic scoping&quot;?<p>He also complains about the digest loop -- how two-way bindings constantly check for changes and impact performance as your number of bindings grow. There is truth to this, but it is easy to write your own directives that only update UI elements when a change occurs. This can easily be achieved in a variety of different ways. (The most universally familiar of which being a simple callback paradigm.)<p>Building a quality application with angular requires you to think, but I would argue that designing a performant application with ANY framework demands the same thing. You might initially think you get some things for free, but everything has its costs. If you want things to happen automagically, without needing to be explicit about the needs of your specific use case, that&#x27;ll cost you. Is this not a near universal truth in programming? People fault the framework when, instead, they should be faulting themselves: their own laziness or lack of clarity.<p>He talks about having a page listing where their UI already had 2000 bindings and how clicking a &quot;load more&quot; button added another 1000 bindings, killing performance. I can&#x27;t understand why you would possibly have that many bindings... for ANYTHING, unless you&#x27;re Doing It Wrong. Why would you need any two-way bindings for explicitly appended information? When the user clicks &quot;load more&quot;, we know something needs to change. If performance is a concern, why would you ever allow that listing to be automatically updated by checking for changes on every digest cycle? Instead, you can either explicitly update the element when the action is called (no two-way bindings), or use a SINGLE binding for the entire list. 1000 bindings? What could possibly be the justification for that?<p>Bindings can be drastically reduced and performance dramatically improved if you work to optimize your code and move from prototyping with built in ng-* components, to crafting components explicitly for your needs. I truly believe the standard ng-* components are meant more for prototyping and to serve as an example for how you can accomplish similar things as your write your own application specific code. Not being clear about this is perhaps one of angular&#x27;s biggest failings.<p>Does it really surprise any programmer or developer that in order to achieve high performance in your application, you must architect explicitly for your use case?<p>To put it another way, in order to make a great application, you need to understand what is happening under the hood. If you&#x27;re using components that you don&#x27;t fully understand, that end up running a bunch of unnecessary operations, is that the framework&#x27;s fault, or your own?<p>Is it really the role of the framework to do your development for you? You can either have things happen automagically, or have things be performant, but not both. This is reasonable and beyond logical, I think.<p>He critiques the language used in the documentation to explain controllers and hangs his hat on what he feels is the misuse of the word &quot;constructor&quot;. His contention is that this is incorrect because the controller functions are being applied to an existing scope, not being instantiated in the traditional sense. Yet, and he even admits this, he is critiquing documentation that is over a year old. The current docs do a better job of clarifying what&#x27;s actually happening. How is this a fair critique of a framework? Cherry picking year old documentation... this just seems silly, and as someone else said, disingenuous. Nothing is perfect, especially out of the gate, especially in open source -- I think we all know that.<p>His further complaints in this section employ the same strategy -- he takes segments from the documentation out of context and explains why they don&#x27;t make sense. He even says that their use of the term &quot;syntactic sugar&quot; to describe the many options for creating components (services, factories, providers) is incorrect because, in his mind, &quot;syntactic sugar&quot; would imply a direct syntax modification to JavaScript or implementation of a custom language parser. Really?<p>Let&#x27;s see what Wikipedia has to say on the subject:<p>&quot;In computer science, syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express. It makes the language &quot;sweeter&quot; for human use: things can be expressed more clearly, more concisely, or in an alternative style that some may prefer.&quot; (<a href="http://en.wikipedia.org/wiki/Syntactic_sugar" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Syntactic_sugar</a>)<p>Soooo, for example, angular&#x27;s service and factory being abstractions over the provider implementation? When you don&#x27;t need the full power of a provider using these higher level functions makes it more concise, easier to use, and &quot;sweeter&quot;... sounds like syntactic sugar to me, unless we&#x27;re just being pedantic for the sake of it.<p>He says, &quot;Angular seems to strive to make things as complicated as possible.&quot; I would argue that this simply isn&#x27;t true, is shortsighted, and borderline insulting to the intelligence and efforts of angular&#x27;s core team. I believe AngularJS is opinionated but it strives to make things as flexible as possible and as a result some inherent complexity exists.<p>In my (almost) 2 years of working with the framework, this is what I’ve found: AngularJS is extremely flexible. Its built in components are great for quick prototyping and its underlying structure provides an excellent FRAMEWORK for creating more purpose built, application specific, code. In my experience, angular is there when you want it to be and quickly gets out of your way when you don&#x27;t need it. This is a robust framework. It is built for rapid prototyping and creating complex, performant applications (when properly executed). It is not baby&#x27;s first framework.<p>How many times have we heard the old adage that, with most things in life, you get out what you put in. This is doubly true for angular (and development as a whole, I would speculate). If you&#x27;re willing to put in the work, AngularJS can be a phenomenal tool in your arsenal. It can also be great for getting a prototype together, but one must understand, that a prototype is just that. Using ng-* components everywhere and expecting everything to work out optimally is just not going to happen. Did you REALLY think it would?<p>To pull a quote from his last paragraph:<p>&quot;... many people like to recommend projects they haven’t used in any depth, because the idea of knowing what the next big thing is feels good. The result is that people choose frameworks largely based on advice from people who don’t know what they’re talking about.&quot;<p>The irony here is palpable. Change &quot;recommend&quot; to &quot;criticize&quot; and &quot;knowing&quot; to &quot;condemning&quot; and I almost needn&#x27;t say more (he says, 8000 words later).
评论 #8564849 未加载
wnevets超过 10 年前
This article the bad parts: all of it.
评论 #8563151 未加载
mck-超过 10 年前
Bad Idea #1 : can be prevented easily with `controllerAs` syntax — this is pretty widely accepted to be best-practice, so the approach that he points out should never be used to begin with<p>Bad Idea #2: can be avoided using gulp. If you are minifying, you should be using gulp anyway, so it’s just a matter of adding a plugin to take care of that<p>Bad Idea #3: this is true, and you have to take care of it for large-scale applications to prevent performance breakdowns. Since angular 1.3 there are one-time bindings as well.<p>Bad Idea #4: This sounds like nitpicking from a JS purist<p>Bad Idea #5: I agree that this stuff is unnecessarily complicated<p>so yeah… there are many ways that you can break Angular :p learning curve is definitely steep.. and there are plenty of edge-cases that will bite you. Despite all that, it’s pretty powerful at what it does, once you get around it…