1

There are several posts and other contents in the internet that claims against naming classes ending with "er" (like manager, controller, helper...). I personally agree with that, but what alternative names could be given to MVC controllers in the scope of web development? I came up with "entry points" or "end points" (like "UsersEntryPoints", for example) but I'm not sure if it reflects exactly what it does.

  • 2
    remove the word 'controller' from the class name – Ewan Feb 21 '18 at 12:05
  • So, instead of calling "CommentsController" you'd call it just "Comments" and handle HTTP requests there? – Talysson Feb 21 '18 at 12:12
  • I would write the code as if its not a web api/site just a library and name accordingly. It helps stop you adding "Service" "Controller" "View" etc – Ewan Feb 21 '18 at 13:56
8

The point about avoiding "smurf naming" is not to think of synonyms for "smurf", but to not use the term. So the thinking goes that if you have a user controller in a folder called Controllers, then just call the class User, rather than UserController.

However, the problem with that is then you end up with a User class in views and in controllers and in models, which makes it hard to distinguish between them.

The point about avoiding "er" classes is that they upset hardcore OO folk who see them as a sign of procedural code masquerading as OO code. Just ignore them and they might get bored and go away one day. Seriously; it's an inane argument.

The term "controller" has a special meaning for MVC. The convention for those controllers is to call them thus. So stick to UserController. Readers of your code will thank you for it.

  • Yeah, that last part is that makes me think. I really think that "controller" is not a meaning name, it sounds exactly the same as "manager" to me but I understand what it does because I've been working with them since a long time ago and the name was already stablished way before I started using it. Never the less what bothers me is the lack of meaning in a name, but I kind of feel that the tradeoff of using a well stablished name over a more meaningful is worth it. – Talysson Feb 21 '18 at 12:32
  • @Talysson, you'll find many MVC frameworks map a URL to a class that ends in Controller, and you'll have to jump through quite a few hoops to change that convention without writing your own framework. Unless your framework does something fundamentally better than what's currently out there, it may not be a battle worth fighting. – Berin Loritsch Feb 21 '18 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.