[rspec-users] Associations should be private
mark at mwilden.com
Thu Oct 2 13:01:47 EDT 2008
On Wed, Oct 1, 2008 at 7:06 PM, David Chelimsky <dchelimsky at gmail.com>wrote:
> Au contraire! You're comparing apples and cadillacs here. Demeter is
> about encapsulation. Interfaces are about abstraction and structure.
> Completely different animals.
Interfaces in that Java book and LOD in this topic were being supported by
arguments of the form "if you need to change things in the future..." There
are some practitioners for whom that's a valid argument, and there are
others for whom it's an anti-argument. YAGNI is the latter. Doesn't make it
right, but it does provide a way to evaluate each of these animals.
> Tracking down all of the trainwrecks in a system is not quite so
> simple. First of all, they are not guaranteed to look the same:
> t = trainer
> a = trainer.animals
> d = trainer.dogs
> dog = dogs
> So when the design seems to want to categorize animals into domestic
> and wild, the first call has to be changed to
> trainer.animals.domestic.dogs.first. Good luck tracking down the
> second example
In a statically-typed language, this would be trivial. In a
dynamically-typed language using BDD, this would be caught by tests.
> Principles/guidelines like YAGNI and DRY and even the
> ever-threatening-sounding Law of Demeter are NOT LAWS. They are
> indicators. Red flag triggers. Red flags are *warnings*, not *errors*.
We agree on that. See my recent post:
In this case, we've got two of these in direct conflict with each
> other, so which one wins? Gotta look at the costs and benefits of each
> and proceed wisely and *in context*
I feel that YAGNI and LOD are at different levels of granularity. I use
YAGNI and TSTTCPW in my daily life (which isn't to say that I always think
they're the best approach). So I approach problems using those principles as
my base. I don't ask myself a hundred times a day whether I should use a
goto statement - I use structured programming as my base. Same with OOP,
readable code, lack of commenting, etc. You can't approach everything de
novo. So I apply YAGNI unless I see a compelling reason not to. The reason
is that the "costs and benefits" of any approach are usually not obvious -
especially when talking about the future.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rspec-users