News for hackers. Stuff that matters.
Re:Test Isolation Is About Avoiding Mocks by henrik_w on Thursday May 15, 2014 @03:54PM (#7751814)
Reducing the knowledge of internal structures is what the Law of Demeter (http://en.wikipedia.org/wiki/Law_of_Demeter) is about. Usually good practice.
Re:Test Isolation Is About Avoiding Mocks by steveklabnik on Thursday May 15, 2014 @04:43PM (#7752118)
DHH has repeatedly asserted that he thinks the Law of Demeter is bad, so that wouldn't work as a justification, at least in response to him.
Re:Test Isolation Is About Avoiding Mocks by jrochkind1 on Thursday May 15, 2014 @05:08PM (#7752253)
Ah, but I think OP is a pretty good explanation of _why_ the Law of Demeter is actually good, although it doesn't use that phrase.

I've been somewhat suspicious of the law of demeter (not firmly on one side or the other), but this article actually helped me see the value of it.

It's not that "you can't do this because it violates the law of demeter." That's a ridiculous cargo cult way to use software design principles (which, yeah, is quite common). Rather, it's, the law of demeter is good because it prevents THIS stuff, which you don't want.

Like, okay, DHH thinks the law of demeter is useless, but he hates things that... the law of demeter is meant to and helps prevent.

Re:Test Isolation Is About Avoiding Mocks by steveklabnik on Thursday May 15, 2014 @05:45PM (#7752436)
I agree with you that the post is a great explanation of why Demeter is good. All I mean to say is "this is just Demeter" is not a refutation of "I think the Law of Demeter is shit and never follow it." (See my links in your sibling, that's a quote.)
Re:Test Isolation Is About Avoiding Mocks by protomyth on Thursday May 15, 2014 @04:51PM (#7752161)
What is his reasoning on it being bad?
Re:Test Isolation Is About Avoiding Mocks by steveklabnik on Thursday May 15, 2014 @05:43PM (#7752429)
Re:Test Isolation Is About Avoiding Mocks by pacala on Thursday May 15, 2014 @05:42PM (#7752419)
There is (immutable) data and there are modules. Encapsulation / Demeter make it hard to work with data. OTOH, Encapsulation / Demeter are good for modules.
Re:Test Isolation Is About Avoiding Mocks by fxn on Thursday May 15, 2014 @06:01PM (#7752511)
He does not say it is bad per se.

What he criticizes is using any of these "laws" and "principles" as if they were truths, as if the argument was based on an axiom or had the strength of science.

They are "inferred" from experience statistically speaking, but in each individual case you need to gauge and check yourself whether those three dots make or not make sense.

It is your judgement in particular code that matters, not the a priori invocation of any "law" or "principle".

Re:Test Isolation Is About Avoiding Mocks by gary_bernhardt on Thursday May 15, 2014 @06:02PM (#7752520)
DHH quote: "I think the Law of Demeter is shit and never follow it."

(from http://signalvnoise.com/posts/3112-how-basecamp-next-got-to-...)

Re:Test Isolation Is About Avoiding Mocks by fxn on Thursday May 15, 2014 @06:09PM (#7752545)
Because he judges a series of dots by themselves, not because any law mandantes anything. He gives a shit about these grandiose names, show me the code and let's discus on that.
Re:Test Isolation Is About Avoiding Mocks by gary_bernhardt on Thursday May 15, 2014 @06:11PM (#7752555)
I was responding to your claim that "He does not say it is bad per se." Calling it "shit" seems like "[saying] it is bad".
Re:Test Isolation Is About Avoiding Mocks by fxn on Thursday May 15, 2014 @06:23PM (#7752613)
If you present a code with ten dots, he will probably say it is bad code. But he won't invoke law of demeter. That's the point I think.

Is like invoking SRP. Fuck that. When you are experienced, you develop a sense on delineating responsabilities in a way that fits your application.

I am not David of course, but I have participated in some discussions with him, and we think very much alike on these topics, I think what I say above is right.

Going to switch to myself now: When people invoke SRP a priori they sometimes end up with one class == one method in a theoretical a priori way.

I don't think that works. It goes in the reverse direction. SRP is inferred, it emerges, it is not applied as if it was a logical proposition.

Re:Test Isolation Is About Avoiding Mocks by derefr on Saturday May 17, 2014 @12:36AM (#7759234)
> When people invoke SRP a priori they sometimes end up with one class == one method in a theoretical a priori way.

That's... not really what SRP means. This (http://blog.8thlight.com/uncle-bob/2014/05/08/SingleReponsib...) was on HN just a bit ago--Mr. Martin being the guy who gave us the term. Let me quote the essential bit:

> And this gets to the crux of the Single Responsibility Principle. This principle is about people.

> When you write a software module, you want to make sure that when changes are requested, those changes can only originate from a single person, or rather, a single tightly coupled group of people representing a single narrowly defined business function. You want to isolate your modules from the complexities of the organization as a whole, and design your systems such that each module is responsible (responds to) the needs of just that one business function.

Re:Test Isolation Is About Avoiding Mocks by jimbokun on Thursday May 15, 2014 @08:56PM (#7753191)
Citing dhh's opinion is not a justification for ignoring the law of Demeter, either, so what's your point?