On Mar 9, 8:00 am, Gavin Kistner <[email protected]> wrote: > Though it's dangerous to attempt to identify emotion from email/text, > I feel from your response that I may have offended you. If so, I > apologize; my intent was not to make a personal attack on you or your > decisions. Rather, I was only trying to express my own opinion about > the method names. If I didn't offend you, and have misinterpreted your > vigorous and thorough explanation of your rationale as > emotional...well, then I also apologize. :)
You didn't offend me at all. I'm sorry if I gave that impression. > On Mar 8, 2009, at 8:35 PM, Jeremy Evans wrote: > > I think belongs_to is stupid method name. A book doesn't belong to an > > author, as that implies ownership. has_and_belongs_to_many is > > probably the stupidest name, as it implies ownership both ways, which > > generally makes no sense. has_many isn't that bad, except even in a > > many to many situation I think has_many would be just as descriptive, > > which is why it's a bad idea to use it for just one association type. > > An interesting point. Does it make sense to say that a teacher "has > many" students, without implying that the teacher owns them? I think > so. But I'd agree that it doesn't make sense to say that a student > "belongs to" a teacher (in lower grades with a single teacher for an > entire grade) or that a student belongs to many teachers (when a > student has different teachers for various subjects) . Or (worse) that > in the many_to_many case that a teacher in any way ever belongs to a > student. Like I said, has_many makes sense where it is used, but I don't like it because it makes sense for both the one_to_many and many_to_many cases, and it only works in the one_to_many case. > > It's easy. On on "MyModel.x_to_y :associated_model" call, the MyModel > > is the x in the associatied_model is the y. So for Jorble > > one_to_many :bongles, Jorble is the one and bongles is the many. If > > the association method ends in many, you use the plural form, > > otherwise, you use the singular form. I suppose it is more natural if > > you come from a database background, where people use terms like one > > to many and many to one (or 1->N and N->1), and nobody uses terms like > > belongs to to describe relationships between tables. > > I do come from a database (and computer-science) background. I > absolutely understand the concept of one-to-many et al. And I don't > dispute that there's an easy mnemonic for remembering which to apply. > It's just that (for me) reading it doesn't describe what's going on. I > have to break out my (super-simple) encoder ring every time I need to > decide which to write, and my (super simple) decoder ring when reading > the code. It's not that I don't understand what one_to_many means, but > rather that it is not clear to me which is the one and which is the > many. Sorry to imply that you didn't come from a database background. Maybe it's just natural to me because I wrote it. :) > It's as though I had a Person object with a method named > #uncle_nephew. Gavin.uncle_nephew( Hayden ). Sure, it's easy to > document that the receiver is the uncle and the argument is the > nephew. And it's easy to defend the ordering from a left-to-right > perspective. But (IMHO) it would be far clearer and self-documenting > to instead name the method "is_uncle_of" or "nephew=". I can't argue with you there. But as you pointed out, you can't use that as a generic naming idiom. > > I like my method calls to make sense. Method calls should be verbs > > only if they are actions. Association methods are the way you > > describe to Sequel how models are connected to each other. There are > > no actions, so I don't see a reason to use verbs. You end up with bad > > method names like has_and_belongs_to_many if you do that. > > I could argue that all method calls that change any state (not purely > functional) can be considered 'actions'. (Isn't changing an instance > variable an action?) So there's some movable conceptual line of what > is setting a property and what is invoking an action. In your mental > model, I suppose, one_to_many is setting a property. In my mental > model, it is causing various methods to be generated. I think of it as one_to_many describing a relationship. And I think of action as having a direct effect, as opposed to setting data/ creating methods that are used elsewhere. If you add an association that is never used, it doesn't really have any effect on the running of your ruby program. > If I were in charge of Sequel (which I'm not, and so of course accept > your decisions) I would probably call them: > references_a > referenced_by > joins_with (or something similar) > > But, it's not a big deal. references and referenced_by are good names, though I don't think joins_with is a good name (references_many as suggested by David Lee is fine). I think *_to_* is a little more obvious as to what is going on, but that's just my opinion. Jeremy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en -~----------~----~----~----~------~----~------~--~---
