Re: [Rails] Rails' inflections are messy

163 views
Skip to first unread message

Paul

unread,
Jul 19, 2012, 7:53:43 AM7/19/12
to rubyonra...@googlegroups.com
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 Wed, Jul 18, 2012 at 8:41 PM, davidcelis <da...@davidcelis.com> wrote:
> Yesterday, I opened a GitHub Issue 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-state-of-rails-inflections/
>
> 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.
>

davidcelis

unread,
Jul 19, 2012, 12:27:05 PM7/19/12
to rubyonra...@googlegroups.com
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:


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.
Message has been deleted

davidcelis

unread,
Jul 19, 2012, 2:23:15 PM7/19/12
to rubyonra...@googlegroups.com


On Thursday, July 19, 2012 11:22:40 AM UTC-7, davidcelis wrote:
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/inflections

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.

Linus Pettersson

unread,
Jul 19, 2012, 3:07:47 PM7/19/12
to rubyonra...@googlegroups.com
At least they should fix the ones that are incorrect...

"Octopus".pluralize should return "Octopuses" and NOT "Octopi"... :)

Colin Law

unread,
Jul 19, 2012, 3:48:23 PM7/19/12
to rubyonra...@googlegroups.com
On 19 July 2012 20:07, Linus Pettersson <linus.pe...@gmail.com> 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

>
>
>
> Den torsdagen den 19:e juli 2012 kl. 20:23:15 UTC+2 skrev davidcelis:
>>
>>
>>
>> On Thursday, July 19, 2012 11:22:40 AM UTC-7, davidcelis wrote:
>>>
>>> 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/inflections
>>>
>>> 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.
>>>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-ta...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rubyonrails-talk/-/rNreNAZ8nB4J.
>
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

davidcelis

unread,
Jul 19, 2012, 3:57:19 PM7/19/12
to rubyonra...@googlegroups.com, cla...@googlemail.com
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 Thursday, July 19, 2012 12:48:23 PM UTC-7, Colin Law wrote:
On 19 July 2012 20:07, Linus Pettersson <linus.pe...@gmail.com> 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

>
>
>
> Den torsdagen den 19:e juli 2012 kl. 20:23:15 UTC+2 skrev davidcelis:
>>
>>
>>
>> On Thursday, July 19, 2012 11:22:40 AM UTC-7, davidcelis wrote:
>>>
>>> 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/inflections
>>>
>>> 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.
>>>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to

Michael Pavling

unread,
Jul 19, 2012, 4:01:29 PM7/19/12
to rubyonra...@googlegroups.com
On 19 July 2012 20:48, Colin Law <cla...@googlemail.com> wrote:
> On 19 July 2012 20:07, Linus Pettersson <linus.pe...@gmail.com> 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?

davidcelis

unread,
Jul 20, 2012, 1:25:20 PM7/20/12
to rubyonra...@googlegroups.com
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.

davidcelis

unread,
Jul 26, 2012, 8:17:32 PM7/26/12
to rubyonra...@googlegroups.com
Any thoughts on this from core members, perhaps? 

Rafael C. de Almeida

unread,
Jul 26, 2012, 9:21:26 PM7/26/12
to rubyonra...@googlegroups.com
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 Com­puter Sci­ence: cache in­val­i­da­tion and nam­ing 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.

davidcelis

unread,
Jul 27, 2012, 11:00:59 AM7/27/12
to rubyonra...@googlegroups.com
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.

Rafael C. de Almeida

unread,
Jul 28, 2012, 1:03:54 AM7/28/12
to rubyonra...@googlegroups.com
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

davidcelis

unread,
Jul 28, 2012, 3:01:38 AM7/28/12
to rubyonra...@googlegroups.com
Rails itself depends on pluralization for the reasons I stated in my last message.

Paul

unread,
Jul 28, 2012, 10:21:23 AM7/28/12
to rubyonra...@googlegroups.com
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. As I often do in that situation, I
deleted those files and changed the name to "MediaOutlet" so it would
act predictably.

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.

This is especially important for constructing stuff in javascript
because the easiest thing is to just assume it is normal and add an
's'.
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-ta...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rubyonrails-talk/-/WTQyy8fiZHkJ.

Matt Jones

unread,
Jul 29, 2012, 12:32:01 PM7/29/12
to rubyonra...@googlegroups.com


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:


 
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

davidcelis

unread,
Jul 30, 2012, 12:34:11 AM7/30/12
to rubyonra...@googlegroups.com
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.

Paul

unread,
Aug 2, 2012, 11:30:33 AM8/2/12
to rubyonra...@googlegroups.com
index: GET /media
show: GET /media/1
edit: GET /media/1/edit
create: POST /media
update: PUT /media/1
new: GET /media/new
delete: DELETE /media

I wasn't suggesting changing this retroactively, I was supporting the
idea of the inflections gem, which would allow an replacement that
didn't require duplicating all the rules in javascript.

davidcelis

unread,
Aug 7, 2012, 5:46:30 PM8/7/12
to rubyonra...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages