5 ms·
I used to have a problem, so I thought to use AngularJS. Now I have a ProblemDirectiveFactory. http://stackoverflow.com/a/15253892/521834 http://stackoverflow.c
by abrkn 13y ago
I used to have a problem, so I thought to use AngularJS. Now I have a ProblemDirectiveFactory. http://stackoverflow.com/a/15253892/521834 http://stackoverflow.com/a/15253892/521834
Show me any code that cannot be written faster and shorter using only jQuery, Underscore templates and a CommonJS compiler. Does not exist. You are writing enormous amounts of glue code to please AngularJS and getting lost in your obsession with tools, imagined reusability and over-complicated testing procedures.
- joelhooks 13y agoStrong assumptions!
- chaddeshon 13y agoSometimes it is smarter for the short and long term just to right a little jQuery in your controller. You are right, don't worry about reusability until you actually reuse something for the 3rd time. If you are going to be doing something a lot (capitalizing the first letter in your example), then I think writing the filter does save you in the long run. Writing the filter doesn't seem worth it when you project is small. When you project gets big, and there are little one off jQuery statements everywhere, it gets unmanageable. The filter allows you to look at your template and immediately know why that word is being capitalized. With jQuery, a year from now you won't remember why/how it is being capitalized, and you'll be grepping for ids and class names.
- arcatek 13y agoAnd when you will leave your enterprise, your code won't be maintainable anymore because the next developers will have no idea about the architecture of your application. Then someday someone will say "well ... nobody understand this code anymore ... let's get ride it, guys. I guess it's time for feature freeze.". Of course, we're talking about some size of application here. If you just want to make a todo list, jQuery is fine. But when dealing with a potentially huge codebase, it is good to enforce practices.
- don_draper 13y agoAngular helps you organize and test your code. How did you test your 50+ onclick functions? Did someone come after you to do maintenance and agree the jQuery was the way to go?
- pgambling 13y agoI wouldn't test 50+ onclick functions. I'd used event delegation to assign the click handler to the appropriate parent element. I'm not experienced with Angular, but the last time I checked it didn't support event delegation :(
- Kiro 13y agoAre you saying you are writing tests for all of your 50+ ng-click functions then? What's the difference?
- defen 13y agojQuery 1.9.1 + Underscore 1.4.4, minified and gzipped is 37,283 bytes. Angular.js 1.0.7 minified and gzipped is 30,254 bytes. So you're actually sending down significantly less code for small projects if you're just using angular. Furthermore, my experience has been the opposite of yours - I find myself writing far less glue/boilerplate code with angular.
- heidar 13y agoI'd be curious to see any large Angularjs apps. Do you know any? How big should single page apps be allowed to be? Is there a clear use case for this to be sensible? This is not a loaded question in case you or someone mistakes it for such...
- dested 13y agohttp://builtwith.angularjs.org/ http://builtwith.angularjs.org/
- adamnemecek 13y agoI would not call it a big app but 5by.com is written in some 2.2KLOC of angular and I feel like it shows some of the strength of the framework.
- abrkn 13y agoCode or it didn't happen
- defen 13y agoIt's clear that you're here to troll or to push an agenda, and not to learn. I personally do not care what technology you use. It's not my responsibility to convince you that your current practices are suboptimal. I'm not a contributor or in any other way affiliated with Angular, I just think it's a really well done framework.
- skore 13y agoI've downvoted a couple of your comments in this thread that were in a similar style. HN isn't reddit. Please educate yourself on the way discussions are conducted here.
- marknutter 13y agoYou are completely missing the point of directives. Your proposed alternative strategy of using "only jQuery, Underscore templates and a CommonJS compiler" will leave you with DOM manipulation code entangled with your controller logic and a nearly untestable mess. Directives are meant to encapsulate any code that directly deals with manipulating the DOM so that stuff doesn't leak into your model or controller logic. You of course don't have to throw everything into directives but then you risk making your code less portable and your tests more brittle. Wrapping a jQuery plugin in a directive is so trivial it's not even worth mentioning, and it certainly doesn't result in "enormous amounts of glue code to please AngularJS". > over-complicated testing procedures And this is where you showed your hand. You can't have written tests for an angular app because if you had you wouldn't have made such a bizarre statement. Angular's dependency injection combined with the fantastic Karma test runner makes testing an absolute breeze.
- kaeawc 13y ago> so trivial it's not even worth mentioning If it is so trivial then it 'is' worth mentioning. Give an example or reference. Personally I like Angular, but I'm learning and finding articles like the OP's are great to read to have others' perspectives on how to work with it.
- marknutter 13y agoI mean it's not worth mentioning in a disparaging way.
- adamnemecek 13y agoE.g. http://amitgharat.wordpress.com/2013/02/03/an-approach-to-use-jquery-plugins-with-angularjs/ http://amitgharat.wordpress.com/2013/02/03/an-approach-to-us...
- abrkn 13y agoPaste a directive here that shows how AngularJS is not bloated.
- Kiro 13y ago
- crabasa 13y ago> Show me any code Here's an example from Miško Hevery's session on Angular.js at Google I/O: https://github.com/mhevery/ng-google-io/blob/demo/app/scripts/main.js https://github.com/mhevery/ng-google-io/blob/demo/app/script... He displayed the equivalent jQuery code side-by-side and the difference was dramatic (spoiler: jQuery was more code).
- abrkn 13y agoDo you have the jQuery code he write for comparison? I assume he re-wrote or copy-pasted a lot of code any experienced developer/team has long ago extracted into small, reusable libraries, such as history management or short-hand ajax requests.
- mst 13y agoThat wouldn't make the comparison invalid - if he's not using anything not supplied by AngularJS, then a comparison to JQuery would also not use anything not supplied by the package.
- granitepail 13y agoHaving worked on a sizable AngularJS project for a good while, now, I can't begin to imagine where you're coming from. The strength of Angular, in my opinion, is that I write ~1/10th the code I'd write using jQuery & Underscore. Event handling, display logic, data binding, directives, resource factories – all of these and more mean I can focus on my business logic as opposed to re-binding events when I update the DOM and the dozens of other trivial bits I have to care about when using jQuery (or Backbone, really). Obviously jQuery/Backbone setups have their place, but to claim that AngularJS makes you less effective is absurd.
- bdicasa 13y agoI've used both Angular and Backbone pretty extensively and I think client side MVC in general makes you less productive. I've been starting to use PJAX with a splash of jQuery for most pages. Only using Backbone / Angular for pages that really require it. Have seen a big productivity boost and apps are as responsive. Too many people are seeing client side mvc as solution to everything. I did at first as well.
- abrkn 13y agoThen you are bad at programming. 1/10th? Code or it didn't happen.
- abrkn 13y agoYou fail to present any case in which AngularJS improves development, maintainability, reusability or testability. AngularJS, much like Ember, Spine, Backbone, TinyMVC, Meteor, ... is good at one thing: Making that Todo demo.