Let's do this refactoring when that actually happens.
> What concerns me most about this is that resistance to cleaning up
> code likely implies a lack of confidence in the test suite.
> Considering how core associations are to Rails, and the not
> insignificant amount of cruft in that code, there should be tests on
> associations like fat kids on an ice cream truck. What are you
> concerned the changes will break, given that all the tests pass?
There is no lack of confidence. But I'm not very much in favour of
refactoring without any performance gains or any obscure bug fixes.
Refactoring like these makes almost all the relevant patches in LH
stale and screws up the history. I just don't think the patch in
question here is worth that.
--
Cheers!
- Pratik
http://m.onkey.org
I myself have had my faire share of frustration when browsing around in
the AR associations code and as anyone who has ever done more than a few
hours of programming knows confusion always – and I mean always! – leads
not only to more bugs but also hinders in adding features to the
confusing code.
I'd argue those "odd bugs"Adam mentioned have already been there. Many
times. There is no *one* bug that shouts "I'm here because this code
needs to be refactored!", it usually is much more subtle than this.
Years of experience generally show though that the harder code is to
understand, the more buggy it will be.
Now *if* there is fantastic test coverage and *if* someone is willing
and able (regarding skills and free time) to give it a shot, I say go
for it: Fork, refactor, push, and show us!
IMHO there's never a better time to refactor than right *now*. Besides
yesterday of course..
Best,
Niels
I believe that Adam already addresses many of these points in his original post:
"This inheritance relationship has already caused its share of bugs, as
mentioned by commenters on the ticket. I fixed two here:
http://rails.lighthouseapp.com/projects/8994/tickets/895-has_one-through-errors.
More importantly, the added complexity created by importing all of the
collection logic and interface into a non-collection association class
just adds to rigidity and potential for odd bugs in the future."
It is hard to write a failing test for bugs that don't exist, but the
existence of prior already-fixed bugs should be considered as a
motivation for doing the refactor.
Furthermore, the existence of bugs isn't normally the primary
motivation for refactoring - but they are a symptom of a needed
refactoring. Complex, hard-to-understand code is a direct motivation
for refactoring, which I think is the point here.
-- Chad
I'm in favor of your patch and have commented on the ticket.
Still, I think there biggest issues with ActiveRecord is something else:
It is basically gluing together bits and pieces of generated and
provided SQL without much concept of what it is doing.
Try anything interesting involving associations, scopes, and a few
joins. You either end up with too many joins between the same tables or
duplicate aliases the DBMS is going to complain about. What about those
naming conventions when the same table occurs multiple times?
ARec needs to take a step back from concrete SQL strings, toward
abstract models of the various SQL statements. This (huge) step would
allow for better modularity, customizability, and easier expression of
programmer intention. I have no idea how to introduce a change such as
this as it would surely void backward compatibility. Sigh, only
dreaming.
Michael
--
Michael Schuerig
mailto:mic...@schuerig.de
http://www.schuerig.de/michael/
Sequel already does that, why not just use it if that's what you want?
Jeremy
Indeed, we've been talking about this for a long time. And Nick
Kallen started the work required to do this with ActiveRelation.
Emilio Tagua is doing a GSOC project this summer to integrate ARel
into AR. Also, Nathan Sobo's Unison is a very interesting take on
integrating a relational algebra into AR associations (which I think
he started as an offshoot of ARel).
--
Josh Susser
http://blog.hasmanythrough.com
Golden Gate Ruby Conf :: April 17-18 :: http://gogaruco.com
Inertia? I've had a quick look and Sequel is indeed appealing. I'll have
a closer look tomorrow.
As Josh points out in another reply, ARec is heading in a similar
direction. I'm wondering whether there's a chance to join forces.
Interesting. If people have been talking about this for a long time, I'm
curious where this discussion has been happening. On this list I can
hardly find a trace of it.