Yesterday, I opened a GitHub Issue<https://github.com/rails/rails/pull/7071> about moving Rails inflections to an initializer. The idea wasn't received well, understandably, as generating a large initializer with new Rails apps is pretty unappealing. However, the core members seemed open to the discussion of alternatives continuing here. For those of you not in the know, inflections (the defined rules for singularization/pluralization) in Rails are currently frozen. What this means is that most pull requests submitted that add, remove, or change inflections are closed and not merged. The reasoning behind this is to avoid breaking existing applications that depend on these inflections, even if they are errant. People are advised to fix (yes, fix) these inflections themselves in their inflections initializer. In my opinion, with a major 4.0 release coming up, inflections should be unfrozen and fixed/cleaned up. There is a lot that is bad in this file, and I don't think fear of breaking existing apps is a good reason to freeze mistakes. People should read the CHANGELOG when updating. They should read the upgrade guides. It's not that hard to redefine the inflection you need in that initializer, and the current inflections are based mostly around exceptions to grammatical rules rather than the rules themselves. If people want specifics, I've written a post about this: http://davidcelis.com/blog/2012/07/18/the-current-... I'm curious as to what others think. I'd like to help make this a better framework, and I've heard a lot of complaints from personal colleagues about how messy the inflections are.
on 2012-07-19 11:47
on 2012-07-19 13:55
I personally don't like them at all. I wish that all the names of controllers/routes/models were unchanged so I wouldn't have to keep deciding whether I needed to pluralize. I remember spending too much time trying to straighten out a scaffold I created named "series". It created a model named "Serie"! I shouldn't have to spend energy figuring that out. It should use the exact name I give it.
on 2012-07-19 18:28
I disagree with this; I think the inflections are important. They're just messy right now. I don't think it's an arduous task to fix them, and I don't think it's unreasonable to take the stance of "Rails can't possibly include every inflection by default." My problem with the current inflections is that it seems like they *were* trying to include every inflection. Now we've got a long list of inflections based on exceptions and irregularities, most of which rarely see the light of day in any Rails application. But they're frozen, so it's difficult to get Rails core to accept fixes. Looking over grammatical rules, the actual list of inflections could be extremely short: https://gist.github.com/3145080 I could be missing something here, but those cover the regular plurals and a couple of irregularities that will show up in Rails apps enough to warrant definition. More irregularities *could* be argued, but personally I think the stance should be that most irregularities should be defined in the user's initializer (which is what Rails core tells people now anyways). But telling people right in the documentation to *fix errant inflections* in their initializer? Yes, let's admit we're wrong. That's noble. But let's fix it, too.
on 2012-07-19 20:23
For anybody who shares my sentiment, until Rails core decides it's time to clean up their inflections, I've published a gem to provide more sane default pluralization/singularization rules: https://github.com/davidcelis/infletions Here's the difference: 4 pluralization rules (down from 21) 5 singularization rules (down from 27) 3 irregularities (down from 7) 1 uncountable (down from 10) Ahhh. Much better.
on 2012-07-20 14:11
At least they should fix the ones that are incorrect... "Octopus".pluralize should return "Octopuses" and NOT "Octopi"... :) Den torsdagen den 19:e juli 2012 kl. 20:23:15 UTC+2 skrev davidcelis:
on 2012-07-20 14:53
On 19 July 2012 20:07, Linus Pettersson <firstname.lastname@example.org> wrote: > At least they should fix the ones that are incorrect... > > "Octopus".pluralize should return "Octopuses" and NOT "Octopi"... :) But then all those applications that rely on the current pluralisation of octopus would break when upgraded. Innumerable applications around the internet would come to their knees. Colin
on 2012-07-20 15:01
So many applications! But in seriousness, this IS a terrible argument, is it not? I'm not crazy, am I? There are CHANGELOGs and upgrade guides for a reason.
on 2012-07-20 15:05
On 19 July 2012 20:48, Colin Law <email@example.com> wrote: > On 19 July 2012 20:07, Linus Pettersson <firstname.lastname@example.org> wrote: >> At least they should fix the ones that are incorrect... >> >> "Octopus".pluralize should return "Octopuses" and NOT "Octopi"... :) > > But then all those applications that rely on the current pluralisation > of octopus would break when upgraded. Innumerable applications around > the internet would come to their knees. :-) Surely all those sites' developers could just override the inflector back to what it used to be, and get on with all the other tasks they need to complete to upgrade to Rails4?
on 2012-07-20 19:26
Yep, the point I've been getting at. People shouldn't blindly upgrade their Rails versions anyway, and when they see errors that a Controller can't be found based on their Model name or vice versa, it should be pretty obvious as to what's going on unless they're clueless about the inflector.
on 2012-07-23 10:42
On Thursday, July 19, 2012 6:53:43 AM UTC-5, paulie wrote: > > I personally don't like them at all. I wish that all the names of > controllers/routes/models were unchanged so I wouldn't have to keep > deciding whether I needed to pluralize. I remember spending too much > time trying to straighten out a scaffold I created named "series". It > created a model named "Serie"! I shouldn't have to spend energy > figuring that out. It should use the exact name I give it. I agree with this some what. There have been times where I needed a singular table name or plural model name. I know I could override which table it points to and do a little foot work on my part. The current state of inflections isn't too horrible, but it should at least be decoupled from Rails core.
on 2012-07-27 02:18
Any thoughts on this from core members, perhaps?
on 2012-07-27 03:22
One thing that have always bothered me about the inflector and this pluralize business is that it only work in English. That make rails newbies from non-english speaking countries have a harder time learning the technology than they should. I know ruby's keywords are already in English, and so are method names and so on. But reading a foreing language is easier; and so is using already defined names. However, a person who doesn't know English very well will not do a good job in naming his own variables and models in English. A famous quote from computer science field goes: "There are only two hard things in Computer Science: cache invalidation and naming things". Imagine naming it in a language you aren't proficient. Perhaps inflection should not be the default. Maybe it should be optional. If you want it, then you can load your language's inflection gem, if it's available.
on 2012-07-27 17:02
I don't think that's really a good option. Some Rails internals already rely heavily upon the inflections; there have to be some pluralizations loaded by default (whether from within the framework, or an inflections gem). If they WERE to be extracted into a gem (which is what I did), it would still need to be bundled by default. Inflections are used in routing, mapping between models and controllers, and a lot of other places within Rails. They need to be there.
on 2012-07-28 07:05
Maybe I'm missing something, but couldn't the default inflection just don't do anything? That is, the plural of any word is the word itself. From the user point of view, it would be like there is no pluralization at all. Cheers
on 2012-07-28 09:03
Rails itself depends on pluralization for the reasons I stated in my last message.
on 2012-07-28 16:22
on 2012-07-29 18:33
On Saturday, 28 July 2012 10:21:23 UTC-4, paulie wrote: > > I just ran into this again. I attempted to call a model "Media", and > the scaffold decided that I meant "Medium", which is NOT a newspaper; > it's someone who has a seance. Not to be a jerk, but you're wrong: http://en.wiktionary.org/wiki/media#Etymology_2 > As I often do in that situation, I > deleted those files and changed the name to "MediaOutlet" so it would > act predictably. > And as a side effect, got a model name that makes it *way* easier to understand what you're actually representing. Until you clarified it, my first guess was going to be that 'Media' was a class representing an audio/video/image file. Here's what would be nice to happen: > > model: Media > controller: media_controller > route: /media, media_path, media_new_path, etc... > params: params['media']['etc'] > > That beats having to call pluralize and singularize all the time and > try to keep it straight. For bonus points, how would the new behavior distinguish between the 'show' and 'index' actions? (currently plural-with-no-args vs. singular-with-one-arg) I suspect you're going to face a lot of pushback from all the developers who *have* managed to "keep it straight", since your suggestion involves breaking every one of their applications. --Matt Jones
on 2012-07-30 06:35
Agreed on all counts. I don't think pluralization needs to go anywhere. I think the resourceful routes and controller names are more representative of what's going on. I just think the pluralization rules need to be cleaner and that the backwards compatibility excuse doesn't work so well for a major 4.0 release.
on 2012-08-02 17:32
on 2012-08-07 23:47
Guys, lets keep in mind that I meant for this discussion to be about how the inflection rules themselves are bad. Not how they're used internally with Rails, but how the file that defines these rules is an utter mess.