Live data from Hacker News

Classy: Cleaner class-based controllers for AngularJS

davej.github.io

41–50 of 59 posts

Re: Classy: Cleaner class-based controllers for AngularJS

#41
post #29

This is actually great for someone learning Angular. It's just a different way of presenting the exact same material. I was completely dumbfounded at first when learning Angular. This would have helped. I very much suggest everyone interested in Angular development to read what the guys at MeanJS.org[1] have to say about structuring modules. It helps me think about my app a lot better. The structure could be cleaned…

I would go with writing directives over using global scope in general, though it's more time consuming to me.

Re: Classy: Cleaner class-based controllers for AngularJS

#42
There's a lot of conversation about the redundant injector syntax in this thread. This is something that ngmin takes care of completely transparently. There's really no need to worry about it in raw, uncompressed source code. Other than that, this provides a nice way to enforce a certain set of conventions, but I'm not completely sold on the quality of those conventions - the most glaring thing being losing references to your watches. Reverse-binding controllers to views through DOM selectors also has a bad code smell IMO, feels a bit like reverting to jQuery madness. I prefer to do this through routing or directives wherever possible.

Re: Classy: Cleaner class-based controllers for AngularJS

#43

I've experienced the problem of unwieldy controllers myself, but angular is already such an intricate, opinionated framework that I can't imagine adding another layer with its own DSL. Good code organization solves a lot of these problems.

I've noticed that particularly in web development there is this trend of writing - and using - countless frameworks that add much more complexity with little gain, and where the response to existing complexity is to... add more of it. IMHO that doesn't seem like a very good way of doing things, since now you have to learn not only JS, but also all these extra indirections piled on top, to understand how your web appl…

Definitely true in general though angular in particular is SO GREAT that it is worth it. But it certainly doesn't need MORE layers like the one in this post.

Re: Classy: Cleaner class-based controllers for AngularJS

#44

There is really no need for this. It adds nothing imo but another layer of sauce over what angular already does properly. If your controllers are getting huge, go refactor into directives and services. I don't see how this would help since there isn't even inheritance? also: app.controller('AppCtrl', ['$scope', '$location', '$http'], function($scope, $location, $http) { // ... }]); vs app.classy.controller({ name: 'A…

Look a little closer - It's not about saving bytes. I ended up coming up something very similar for my projects and it made a notable difference in defect rate. - Removes the need for positional arguments for constructor injection, so you only have to list your dependencies once. This one seems minor but can be a major frustration and a source of bugs when working with lots of services. - Moves actions out of the sco…

"- Moves actions out of the scope and onto the controller itself, where they belong"

Based on the Classy's docs, it doesnt "move" actions out of the scope and onto the controller, but the other way around. It adds controller's actions to the scope unless you prefix the names with an underscore.

Based on my experience debugging angular performance issues associated with expensive $digest cycles, I do NOT WANT it to happen automagically. I only want those functions on the scope that i explicitly place there.

Re: Classy: Cleaner class-based controllers for AngularJS

#45
post #29

This is actually great for someone learning Angular. It's just a different way of presenting the exact same material. I was completely dumbfounded at first when learning Angular. This would have helped. I very much suggest everyone interested in Angular development to read what the guys at MeanJS.org[1] have to say about structuring modules. It helps me think about my app a lot better. The structure could be cleaned…

I would go with writing directives over using global scope in general, though it's more time consuming to me.

But I need some filters to be "global" and some to be "local". I need to call some in different modules, while some are useful only in one particular module.

I haven't found out how to do this yet. Not fixing it until it breaks, even if that means I'll have to re-write parts of the app.

Re: Classy: Cleaner class-based controllers for AngularJS

#46
post #29

This is actually great for someone learning Angular. It's just a different way of presenting the exact same material. I was completely dumbfounded at first when learning Angular. This would have helped. I very much suggest everyone interested in Angular development to read what the guys at MeanJS.org[1] have to say about structuring modules. It helps me think about my app a lot better. The structure could be cleaned…

I just want to let you know that I really appreciate your empathetic suggestions for those [like me] trying to learn intermediary aspects of AngularJS; of which I am going to relate to—the learning of how to walk——and then applying that knowledge to break atmo and venture into the stars. :)

TLDR; THANK YOU (Intermediary AngularJS learning–curve is friggin hard.)

Re: Classy: Cleaner class-based controllers for AngularJS

#47
post #46
post #29

This is actually great for someone learning Angular. It's just a different way of presenting the exact same material. I was completely dumbfounded at first when learning Angular. This would have helped. I very much suggest everyone interested in Angular development to read what the guys at MeanJS.org[1] have to say about structuring modules. It helps me think about my app a lot better. The structure could be cleaned…

I just want to let you know that I really appreciate your empathetic suggestions for those [like me] trying to learn intermediary aspects of AngularJS; of which I am going to relate to—the learning of how to walk——and then applying that knowledge to break atmo and venture into the stars. :) TLDR; THANK YOU (Intermediary AngularJS learning–curve is friggin hard.)

You're welcome. I am an AngularJS neophyte as well... but the mental picture I have of the framework is definitely clearer than it was two months ago!

Re: Classy: Cleaner class-based controllers for AngularJS

#49
post #44

Earlier quoted context omitted.

Look a little closer - It's not about saving bytes. I ended up coming up something very similar for my projects and it made a notable difference in defect rate. - Removes the need for positional arguments for constructor injection, so you only have to list your dependencies once. This one seems minor but can be a major frustration and a source of bugs when working with lots of services. - Moves actions out of the sco…

"- Moves actions out of the scope and onto the controller itself, where they belong" Based on the Classy's docs, it doesnt "move" actions out of the scope and onto the controller, but the other way around. It adds controller's actions to the scope unless you prefix the names with an underscore. Based on my experience debugging angular performance issues associated with expensive $digest cycles, I do NOT WANT it to ha…

But angular only watches functions you tell it too. What's the harm in attaching a function to the $scope if it isn't used by an angular expression?

Re: Classy: Cleaner class-based controllers for AngularJS

#50
post #15

There is really no need for this. It adds nothing imo but another layer of sauce over what angular already does properly. If your controllers are getting huge, go refactor into directives and services. I don't see how this would help since there isn't even inheritance? also: app.controller('AppCtrl', ['$scope', '$location', '$http'], function($scope, $location, $http) { // ... }]); vs app.classy.controller({ name: 'A…

Thanks for the feedback. I would argue that the Classy example is more expressive and crucially it is DRY. Edit: > One of the brilliant things about angular is that it provides a proper structure that anyone that needs to write angular needs to adhere to Angular doesn't provide structure for controllers, they are just javascript functions. If you want to add structure it is up to the individual developer to decide ho…

I would argue that if your controllers are getting that complicated, then you're doing it wrong.
Post reply on HN