Preferences

>Many would not even see the problem here, and just as children don't know cars can hurt, juniors don't know just how destructive this anti-pattern can be to performance, separation of concerns and long term code base maintenance.

Yup, I don't get it. I guess not only am I eternally doomed to be a junior dev but also am being compared to a child, a monkey typing at a typewriter, but also someone who doesn't know JS at all. Feels good man.

Other than some horribly obtuse undefined checking, there's no explanation of what the problem is. The argument seems to be that the controller depends on $scope. I... I thought that was the point. From the first line of documentation on controllers:

>In Angular, a Controller is a JavaScript constructor function that is used to augment the Angular Scope.

If the idea is that this is a bad habit to bring elsewhere, fine. Some more explanation would be nice, but whatever. But the implication is that this is a trap within the context of Angular dev itself.


This article only did one thing for me - demonstrate that the author himself doesn't understand Angular or the problems. I don't know Angular that well myself, but the author knew anything more than I did, he'd be able to spend the extra 30 seconds to write the refactored code.

Dismiss this article. It's a waste of time and energy. In fact, I really shouldn't even be wasting my time commenting on it.

>This article only did one thing for me - demonstrate that the author himself doesn't understand Angular or the problems.

Seems pretty evident from the horrible jankiness of this blog. Heavy as shit and it loads on the 5th try.

Try to load it on mobile. What a train wreck.
It just says "Loading" on the latest version of Chrome with zero plugins...

And now it says 500

> Error details are currently disabled. Please set StaticConfiguration.DisableErrorTraces = false; to enable.

Ad hominem. I can't really comment on the article itself since I don't understand anything about Angular, but let's do our best not to just throw a bunch of random stuff at the wall and hope something sticks just to justify our lack of understanding of the author's point.
Believe me if the blog wasn't built using angular I wouldn't have said anything.
The thing that struck me about it was that the $scope.displayName() function shadows itself by setting $scope.displayName again:

        $scope.displayName = function () {
            if ($scope.anonymous()) {
                return;
            }
            $scope.displayName = $scope.name;
        };
I have no idea how that's related to Angular, though. It looks like it's just bad programming practice.
I agree completely. You wouldn't do this any ANY language let alone Angular. However, I get he is trying to make a point that junior developers are using the $scope too trivially therefore causing slow performances, but this can be easily overcome by just incorporating better conventions into your codebase.
Yes not to mention that displayName() will crash next time it will get called.
I don't know Angular at all. But it appears that the example with $scope is not respecting the MVC design pattern. It's all been flattened and merged. The controller should only update the model. And the view should only get state from the model. In the example, the controller wraps the model and presents itself to the view as the model and controller. So now to write a test of the view, you can't just create some dummy model, you have to create a mocked up controller.
Well, there's a good reason why $scope and controllers will disappear with Angular 2.0. $scope is convenient, but also a massive source of problems. There's workarounds for those problems, but those workarounds wouldn't even be necessary if this aspect of Angular had been designed better.

Angular has some great stuff, and some really necessary ideas and principles that were sorely needed in Javascript. I love working with it, most of the time. But it also has some serious design errors.

This is anecdotal, but I once found this incredible use of $scope while viewing the source for a sports page: https://gist.github.com/tcrosen/96279e39f9b0fb85c266
I just started learning Angular and that code smells. Why wouldn't you make some sort of object for all of those and assign the object to scope?
I think anyone who knows Angular well would agree - it's a joy to work with, but it isn't perfect. Angular 2.0 is a step in the right direction in many ways.

This blog post is pretty horrid though.

I find myself moving more of my code into pure JS & borrowing concepts from languages like Java (interfaces, abstract classes, etc.) to increase agility in the event I want to move towards using a different library/framework. I gave a talk related to this idea of a frontend SOA about a week ago - here are the slides: http://slides.com/wesleycho/soa-angular

Totally. I like Angular a lot, and I'm not blind to its drawbacks. The code sample in the blog post has room for improvement, but I don't understand what he thinks it demonstrates. Yeah, it's a little weird that controllers don't expose their own functions, that instead you attach functions and data to the $scope. But if that's the way you do it Angular, I don't understand what makes it a bad habit to learn.
He's added a link in the comments to http://csharperimage.jeremylikness.com/2014/11/the-top-5-mis..., which makes a strong argument. It's too bad he couldn't articulate this in his post.
agreed, some explanation on what's actually wrong here would be nice
One thing that definitely can be improved is using "Controller As" syntax. It solves most of the $scope issues.

Here's a good writeup: http://toddmotto.com/digging-into-angulars-controller-as-syn...

This item has no comments currently.

Keyboard Shortcuts

Story Lists

j
Next story
k
Previous story
Shift+j
Last story
Shift+k
First story
o Enter
Go to story URL
c
Go to comments
u
Go to author

Navigation

Shift+t
Go to top stories
Shift+n
Go to new stories
Shift+b
Go to best stories
Shift+a
Go to Ask HN
Shift+s
Go to Show HN

Miscellaneous

?
Show this modal