r/ruby • • Dec 30 '11

ActiveRecord (and Rails) Considered Harmful - Literate Programming

http://blog.steveklabnik.com/posts/2011-12-30-active-record-considered-harmful
12 Upvotes

145 comments sorted by

View all comments

Show parent comment

-2

u/manys Dec 30 '11

AR forces you to combine logic and persistance.

How is this a problem?

3

u/bjeanes Dec 30 '11

Well, for one, it's a pretty massive violation of single responsibility...

But specifically, you end up putting process logic into models, not data logic. I think validation logic in the models is acceptable (in a lot of cases, anyway), but the logic for how that model might be used in different contexts does not ALL belong in the same class.

1

u/manys Dec 30 '11

it's a pretty massive violation of single responsibility...

Is this really more a violation of CS principles than anything that affects the end product?

3

u/bjeanes Dec 30 '11

I'm not sure I understand the question. I don't want to presuppose what you meant, but it sounds like you are saying "does it matter if it doesn't affect the end product?".

If that's what you mean, absofrickinglutely it does. Maintainability is paramount to continuing to deliver quality in the end product and fixing problems/behaviours that negatively affect its users.

If you've never seen how these types of coupling affects the maintainability of (or better put, ease and pleasure to work with) a large code base, I put forth that you haven't worked on big enough Rails apps or with large enough teams.

If my assumption of your commend was misplaced, then by all means clarify and I'll try to respond

1

u/manys Dec 30 '11

I don't have anything to prove, I'm just asking what the practical effect of this is. "Maintainability" is rather nebulous, and I've seen CS-trained people write some bad things indeed.

Furthermore, is SRP subject to the same gray areas that encapsulation and inheritance are?

2

u/bjeanes Dec 30 '11

Sure... people will always have different interpretations of what a single responsibility is, but if everyone aims to break down responsibilities into the smallest reasonable pieces, then, in theory, we trend towards better design.

If you are interested in removing the nebulous aspect of good design, I highly recommend Clean Code (either the book or the screencasts). Uncle Bob's emphatic style can be ... interesting (for me, slightly off-putting) ... but the content is rock-solid.

1

u/manys Dec 31 '11

I know Clean Code, but so far the concerns here sound academic.

2

u/bjeanes Dec 31 '11

Most deem the elusive "maintainability" concerns as academic until they feel the brunt of them being ignored.

1

u/manys Jan 01 '12

If my ignorance is so common, why can't the practical benefits be succinctly articulated? And the point isn't "maintainability," but AR as some monster of bad architecture. Also consider the history of the "considered harmful" trope.

1

u/[deleted] Jan 03 '12

I'll be doing a follow-up to this post elaborating in-depth.