Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pluralize and naming convention #48

Open
plehoux opened this issue Sep 28, 2011 · 1 comment
Open

Pluralize and naming convention #48

plehoux opened this issue Sep 28, 2011 · 1 comment

Comments

@plehoux
Copy link

plehoux commented Sep 28, 2011

In the model and scaffold generators it would be interesting to use and adapt rails naming convention.

Model would be singular and collection plural by default, it would be enforce by the generator.

class App.Models.Category

class App.Collections.Categories

Since most of the time the relationship between model and collection is 1 to 1.

And frankly App.Collections.CategoriesCollection feel a bit repetitive.

@rupert-madden-abbott
Copy link

TL;DR

Instead of removing the collection at the end of a class name, we should instead remove the second level of namespacing e.g. App.CategoriesCollection instead of App.Collections.Categories and this should be extended to all other class types (routers, views and models)

Long Version

Initially, I was in favour of your idea but after thinking this through, I have decided against it for a number of reason:

1) Regular Plurals

I think the most important convention to follow is that there should be a 1:1 relationship between classes and files. This is currently being broken because models and collections are placed in the same file but there is a proposal here to change this: #32

If that proposal were accepted, and I think it should be, then what about resources that have a shared singular and plural word e.g. sheep. This would mean you would have sheep.js.coffee in models and sheep.js.coffee in collections. Open them both up and you can't distinguish them in a tabbed text editor.

2) Breaks Rails Conventions

The convention in Rails is that everything but the model has the type of the class appended to it's name. Controllers, helpers and mailers all follow this convention and backbone is correctly extending this convention to views, routers and collections.

3) Internally Inconsistent

To suggest that collections should break the above convention raises the question of why routers and views should be different (Models are already internally inconsistent but this inconsistency already exists in Rails and conformity to Rails is more important). To suggest that the same change should be extended to routers and views makes both of the above problems more problematic. The first problem would occur with any sort of plural as you would have a router with foos.js.coffee and a collection with foos.js.coffee. And the second problem would be worsened because this is a complete break with the Rails conventions. However, to have this internal inconsistency means that people might be caught out.

Alternative

However, the repetitiveness does bother me. Perhaps, therefore, it would be better to lose the second level of namespacing as this would resolve the repetition without resulting in any of the above problems. In other words, we should have the following:

class App.Foo extends Backbone.Model
class App.FoosCollection extends Backbone.Collection
class App.FoosRouter extends Backbone.Router
class App.Foos.BarView extends Backbone.View

Additionally, this has the advantage of being able to lose the App.Views.Foos ||= {} at the top of every view file and simply put window.App.Foos = {} into app.js.coffee.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants