Live data from Hacker News

Mistakes AngularJS Developers Make

airpair.com

21–30 of 74 posts

Re: Mistakes AngularJS Developers Make

#21

That first (and, to the extent that the author relates the two, second) point feels pretty dubious. I imagine most adherents of the "directory by feature" camp come from the Django-like world, while "directory by type" campers have Rails-like backgrounds. I haven't found a concrete, objective reason to use one over the other. I tend to find a hybrid, "directory by feature" organization mirrored in each of the MVC rol…

I tend to do it by application domain, not necessarily feature or type. Domain usually encapsulates the things that need to work together and provides clear lines for SOC.

Re: Mistakes AngularJS Developers Make

#22

That first (and, to the extent that the author relates the two, second) point feels pretty dubious. I imagine most adherents of the "directory by feature" camp come from the Django-like world, while "directory by type" campers have Rails-like backgrounds. I haven't found a concrete, objective reason to use one over the other. I tend to find a hybrid, "directory by feature" organization mirrored in each of the MVC rol…

I think what you describe is a great approach.

The reason I claimed it was a mistake for angularJS devs was that angular seed and yeoman lead to doing directory by type, which I think becomes a burden as an app scales.

Re: Mistakes AngularJS Developers Make

#23
These types of articles are great, but too frequently I see phrases such as, "It makes testing much simpler" sprinkled throughout them without any justification. These claims are generally not untrue, but it seems like it would be appropriate to demonstrate scenarios of the unit and e2e tests actually being affected by decisions in the application code.

Re: Mistakes AngularJS Developers Make

#24

Hey - #8 regarding "consulting the prototype chain if the value is an object" is something of an oversimplification, and slightly incorrect. The prototype chain is more or less always consulted because that is the only way to evaluate the property on a child scope. What is happening in the first example is that the ng-bind directive is creating a new entry on the child scope, called "user", which overwrites the refer…

Yeah I agree it's an oversimplification. It's tough when writing a piece like this where a deep level of language knowledge is required to make a clear explanation. I tried to lead people toward the cause without getting bogged down in too many details.

Thanks for the example!

Re: Mistakes AngularJS Developers Make

#25

Not mentioned: Coding things so that your site content is invisible to the Google search engine. Which is ironic considering Google's support of Angular

Except that the crawler now executes a lot of Javascript: http://googlewebmastercentral.blogspot.com/2014/05/understan...

Re: Mistakes AngularJS Developers Make

#26
> Whether using Sublime, Visual Studio, or Vim with Nerd Tree, a lot of time is spent scrolling through the directory tree.

There might be a lot of reasons to use dir-by-feature or dir-by-function but if the above is a problem you should probably get a better editor.

EDIT: or use yours better.

Re: Mistakes AngularJS Developers Make

#27

> Whether using Sublime, Visual Studio, or Vim with Nerd Tree, a lot of time is spent scrolling through the directory tree. There might be a lot of reasons to use dir-by-feature or dir-by-function but if the above is a problem you should probably get a better editor. EDIT: or use yours better.

I actually close my file browser "side bar" in Sublime and just open files with the "Goto" command (⌘ P). With strict naming conventions I find this to be quicker than navigating a file browser.

Re: Mistakes AngularJS Developers Make

#28
post #3

Grouping files by feature has made navigating and reasoning about a codebase so much easier. I've even found myself grouping stylesheets & test files alongside templates and app code, it really helps enforce the idea of composing smaller apps together. Google has released a recommended app structure similar to this as well [0], though I haven't actually seen it being used too often in the projects I've come across. […

It doesn't necessarily make sense when you have a team working on different things, front-end devs working on the templates and back-end devs working on services, etc.

Furthermore most likely you will be sharing many partial templates or widgets between different views and sections in your app. So those have to go in some sort of common views folder, losing much of your grouping.

I wouldn't say either way is right or wrong, it just depends on your workflow, size of the app and size of the team working on it.

Re: Mistakes AngularJS Developers Make

#29
great advice here, I would have liked to see some code examples for #4, b/c I am currently struggling with a ng codebase where the controller are doing way too much in my opinion. using ui-router helps some, but, I would love to see more ways to keep the controllers slim.

Re: Mistakes AngularJS Developers Make

#30
post #9

Point 3 about "Dependency injection" is often not needed. Just use ng-annotate before minify/uglify, and it will convert the code to the array syntax for you. It handles most of the cases, leaving your code without the ugly array stuff. It doesn't work for everything, though, so suddenly it blows up. So if you want to be 100% sure your code works as intended do it manually.

I haven't found anything that doesn't work either automagically or with explicit annotations[0].

[0]: https://github.com/olov/ng-annotate#explicit-annotations

Post reply on HN