4 ms·
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 y
by hcho 12y ago
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.
- DrJokepu 12y agoHe talked about ng-min and why he thinks it's a bad idea.
- grumblestumble 12y agoAnd his reasoning around that was inanity disguised with high concept. He already advocates for a build process to minify code, ng-annotate simply expands the condensed DI syntax to the array notation.
- saidajigumi 12y ago> And his reasoning around that was inanity disguised with high concept. To elaborate: invoking the argument "you reduce to the Halting Problem, suxxor!" without some concrete examples of how the practical problem (i.e. ng-min implementation) encounters difficulties is disingenuous. It's not uncommon to be able to cover some very useful space of a real-world problem, skirting "inside" a problem which is theoretically limited by the Halting Problem or similar. Occasionally you hit a limitation in your algorithm and add a special case, further claiming practical territory from The NP-Complete Beast. In this case, the strict di enforcement that baconner mentioned in this thread provides an escape hatch: if you're using ng-min while having di enforcement enabled, you'll at least get warned if something goes amiss. If so, add your manual DI annotations, maybe file an ng-min bug, and move along.
- baconner 12y agoThere's also a new strict di enforcement option that'll make angular error if you don't have the min friendly di syntax in use. That's the best way imo and probably what angular should've always done.
- nawitus 12y agoIt's "insane" to require a post-processing step to fix a bug in a single framework.
- arnarbi 12y agoMaybe your use of quotes is to make fun of the article, but in any case, I'll say this: I disagree it is a bug, rather it is a shortcoming of a minifier that it does not preserve the semantics of the input program. Since this shortcoming is hard or impossible to overcome completely, case-specific post-processors to help out the minifier sound reasonable to me.
- nawitus 12y agoI think it's simply a flawed design to use reflection to read function parameter names and then use that information to apply semantics. I think parameter naming is something that shouldn't directly be semantic, as that's what most developers except. If, for example, I'm supplying a callback function to a library, I don't except the library to read the parameter names and then do stuff differently depending on the variable naming I happened to use. I think your point about the minifier being "broken" is a good one, but the real problem is with AngularJS in my opinion.
- arnarbi 12y agoI agree, it's flawed design and a crutch that comes about due to the lack of a better type system. But the cited reason (that it doesn't work with a minifier) is bogus.
- general_failure 12y agoIsn't this exactly what Active Record in Rails does?
- bronson 12y agoNo, ActiveRecord never looks at argument names. (unless you're talking about Ruby's named parameters, which is nothing like Angular's DI and not AR-specific)
- trey-jones 12y agoOr just get into the habit of writing minifiable code. I think the benefits of using angular (dirt-simple two-way binding) largely outweigh the criticisms levied here, especially for simple applications. I have written large and complex applications with routing, and there were a lot of difficulties, but I think that is probably true of any framework that tries to do as much as angular.
- DonHopkins 12y agoDecades ago I got out of the habit of writing C code that was easy for the compiler to translate into VAX machine language instructions. I didn't realize those skills I let atrophy might someday became useful again for JavaScript. When do you think schools teaching JavaScript should instruct their students how to write easily minifiable code? Is that an appropriate topic for JavaScript 101, or is it more of a graduate level thing? Can you please suggest any good online course where I can learn this important skill that you're suggesting all JavaScript programmers should have? Has Doug Crockford written a book called "JavaScript: The Minifiable Parts"? Does Google test job candidates for the ability to write minifiable JavaScript code on the white board during job interviews, by giving them a dry erase marker that's almost run out?
- trey-jones 12y agoNo need to go overboard there Don. In fact, my statement was really intended to mean "minifiable" in the sense of an angular application. That is, following documented best practices for writing a minifiable application in angular as described here: https://docs.angularjs.org/tutorial/step_05 https://docs.angularjs.org/tutorial/step_05
- DonHopkins 12y agoBy "especially for simple applications" do you actually mean "only for extremely simple applications"? So do you really believe that the insane scoping madness described in the article, and the fact that Angular's new templates breaks HTML syntax making it impossible to edit/validate/transform/generate/consume them with standard off-the-shelf HTML tools, are really not big issues, and dirt-simple two-way binding outweigh those problems, and are impossible to do without causing those other problems in the first place? Since the order a user fills out text fields on a web page affects the scope in bizarre unexpected ways, shouldn't Angular automatically disable the offending second text field until the first is filled out, and provide tooltips and help text explaining to users why they're disabled, to force users to enter them in the correct order, that will not undermine the intent of the developer? Is that the kind of implicit magic that you expect from your full service front end web development stack, that makes it all worth it in the end? Personally, I'd rather have a scoping mechanism that's less magical and astonishing, and more deterministic and predictable. And a templating system that doesn't forsake and reject the rich existing ecosystem of HTML and XML tools.