cgross / generator-cg-angular

Yeoman generator for Enterprise Angular projects.
MIT License
592 stars 198 forks source link

Putting Ctrl in the name of the controller is redundant. #64

Open LegalizeAdulthood opened 10 years ago

LegalizeAdulthood commented 10 years ago

It will appear in the markup as ng-controller="Foo" so it's a violation of DRY to generate ng-controller="FooCtrl". The reasoning behind this preference is pretty well covered in this blog post, so I won't repeat it here.

dancancro commented 10 years ago

There is not a lot of agreement about how to do things with Angular, but appending "Ctrl" or "Controller" to the end of the controller name is one sparkling twinkle of unity in the vast dark scary ocean of igottadoangularjsmywaysoscrewyou.

Here is my collection of the alternatives. The controller names are currently shown on line 214. John Papa in his Pluralsight course is the only one in my collection to have not put redundant suffixes on the controller names.

What you're saying makes sense to me. But agreement makes even more sense to me. Maybe they all do it this way because it would be confusing to just see "Foo" somewhere by itself where it's hard to tell whether it's a service or a controller or maybe it would be hard to run a search through lots of files for every reference to a controller. I dunno.

eduardoinnorway commented 10 years ago

Why not having this as an option?

Do you want to add suffix "controller" to new controller "dashboard"? y/n Or as a flag would even be better.

LegalizeAdulthood commented 10 years ago

vast dark scary ocean of igottadoangularjsmywaysoscrewyou.

This made me laugh! Yeah, I see lots of people doing different things in Angular. I like the DRY reasoning, but I see that even AngularJS.org puts the redundant "Controller" suffix on the names. So I can go with the flow, I suppose. Of course, using that reasoning, as a Windows programmer I'd have ugly hungarian notation everywhere. I resisted that one and eventually even Microsoft came around -- the .NET coding standard specifically bans hungarian notation. Sometimes sanity does win, even if it takes multiple decades.

Feel free to close this if you want.

jancel commented 10 years ago

Nice conversation. I think the appendage is necessary though redundant. In my world, I get confused if the Ctrl isn't there, even if it is in the Controllers folder (actually, it's in my editor).

When in Sublime or MacVim or whatever, they only show the file name. So when I have a few modules open in 4 panes and and a collection of services with the same or similar name, the Ctrl suffix helps.

Am I the only one that has this issue? Any better way around it in your experience @LegalizeAdulthood

LegalizeAdulthood commented 10 years ago

@jancel The funny thing is that I was going off John Papa's blog post as referred to me by a coworker and this was the only one in the matrix that recommended not using a suffix. So I guess I'm in the minority there. So far, our project is small but we know it's going to become quite large, which is why we're looking at yeoman generators and naming conventions, etc. Following the Shu Ha Ri progression, I'm inclined to say that we, as Shu angular developers, should follow the conventions of the community before we decide to change the rules. For myself, I'll probably be using WebStorm as my IDE and I don't think the lack of a Ctrl suffix would harm me in that environment, but I can see it getting annoying if you're using something like paned vim where the most indication you have of context is filename.

cgross commented 10 years ago

I'm a little ambivalent about this myself. I don't mind doing things differently if they are smarter decisions (this generator was placing controllers/services/etc in their own files and placing controllers, stylesheets, and partials together before it was cool). I could see removing the "Ctrl". I really hate it when I see services called "XxxxxService" because its redundant and this is basically the same thing.

That said, you never inject controllers so it doesn't affect anything too much to keep it how it is.

martin-s commented 10 years ago

In my opinion class names and file names should be identical. This is a common approach for other languages as well. So, "FooCtrl" should also be reflected into file name "foo-controller.js" :-)

bolora commented 10 years ago

I think some redundancy is not bad specially when other people have to come behind you and deal with your code.

storkme commented 10 years ago

I would be inclined to point at...

I am a big fan of the convention & consistency in this case.

eddiemonge commented 10 years ago

I like to append Ctrl and Filter as factory, service, provider, value and constant are all service-based objects that are somewhat class like. I dislike how Angular's DI doesn't let you specify the type for a dependency so having a controller and a service named the same thing gets fun.