Ruby on Rails Friday, March 28, 2014

On Fri, Mar 28, 2014 at 6:04 AM, Matthew Riley
<matthew@matthewriley.name> wrote:

> If Engine were to inherit ActiveRecord, would that affect your decision to
> set a default instance?

It depends. Theoretically, the more baggage something drags in, the
less you want to be coupled to it. Kinda like with people. ;-)

But in reality, well... see below.

> In such a case, Car would be effectively coupled to both Engine and
> ActiveRecord.
> Also, do you find Rails developers in general care about loose coupling?

In my experience, most Rails devs aren't going to take the time to
decouple from AR. Rails is very opinionated, and one of its opinions
is that your models (at least the ones that get stored in the
database) should inherit from AR::Base. Yes, it helps makes your
tests much faster, swapping out databases much easier, etc. if you can
cleanly separate the concerns of business logic versus storage. But
it's not the golden path. The tutorials don't tell you how. It's not
easy. It takes some advanced thinking to even *care* about it, let
alone actually *implement* it. So... while many devs will care deeply
about not coupling their own models to *each other*, most seem
perfectly OK with, or at least resigned to, having most of them
coupled to AR::Base.

I've read some stuff on how to decouple the models from AR and still
have the benefits it brings, and tried to do it in a couple little
exercises, but still don't have a good intuitive feel for the process,
especially what step is next and *why*. Most of what I've read, makes
several leaps where I can see the benefit in hindsight, but still
don't see/understand any signs pointing in the immediate directions.

-Dave

--
Dave Aronson, freelance software developer (details @ www.Codosaur.us);
see also www.PullRequestRoulette.com, Blog.Codosaur.us, www.Dare2XL.com

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAHxKQiho55_of%3DBi_bcpHS57OkGzvWY322eAGiUU-j37pkRn7w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment