While reading the CakePHP books I recently reviewed here, a question emerged for which I don’t have an answer: what’s the benefit of the singular/plural conventions we have in CakePHP for me as a framework user?
With singular/plural conventions I mean the following conventions every new baker has to learn while doing his first steps with Cake:
- Table names are plural (e.g. posts, categories, request_tokens)
- Model names are singular (e.g. Post, Category, RequestToken)
- Controller names are plural and ending with “Controller” (e.g. PostsController, CategoriesController, RequestTokensController)
I follow those conventions automatically, but I have to admit I don’t see any real advantages in the distinction between singular and plural names at the moment. On the other hand, the disadvantages are they only work if you use English names (else you have to define your own rules in app/config/inflections.php), they make the learning curve steeper, and if you look at tables as objects it is not that logical to use plural names for them…
Please don’t get me wrong, I think it is a good thing to have naming conventions, but I also think the current conventions could be simplified, to something like:
- Table names are singular (e.g. post, category, request_token)
- Model names are like table names, but camel-cased (e.g. Post, Category, RequestToken)
- Controller names use the model names plus “Controller” (e.g. PostController, CategoryController, RequestTokenController)
You would get all the benefits of naming conventions without having to care whether a name has to be singular or plural. And the conventions would also work for people who prefer to use names in their native languages.
I know, those singular/plural conventions probably won’t disappear, as they are core conventions and a change would affect many Cake applications… At least I learned something about the design of conventions from this example ;-)