[Cs5500] Fwd: Law of Demeter / Scientific Community Game

Karl Lieberherr lieber at ccs.neu.edu
Thu Sep 22 14:01:52 EDT 2011


Enclosed is an interesting discussion with a Google employee who
promoted the Law of Demeter inside Google.

My question is:
Are the classes in our SCGCourt system easy to test. Are they easy to isolate?

Think about this as you read the SCGCourt code and write your own.

-- Karl

---------- Forwarded message ----------
From: Misko Hevery <misko at hevery.com>
Date: Mon, Sep 19, 2011 at 1:51 PM
Subject: Re: Law of Demeter / Scientific Community Game
To: Karl Lieberherr <lieber at ccs.neu.edu>


Hi Karl,
>> Taken literally, I don't agree with one of your statements:

Perhaps it should not be taken literally.
What makes code testable is a complex statement, depending on a lot of
things. In your specific example you are demonstrating a leaf
function. That is a function which has no more collaborators. In such
a case, all other things being equal it is harder to write tests for
your example, then say for absolute value function. But perhaps harder
is the wrong word here. It is not harder, it is just that your example
has more corner cases and hence it has larger surface area for
testing. To put it differently is it harder to build a single family
home or an apartment building. Apartment building is more complex, and
hence takes more work, but it is not harder, as in you don't need to
have some skills which you don't have when building a family house.
Bigger != harder, bigger == more work.
But it turns out that in writing tests for applications, the question
is not that of surface area, but rather than of skill. Testing a leaf
function is easy on the skill level, but writing a test for an
application is very hard, and it is not just that there is more of it.
you really need to have more skills. So it turns out that whether or
not you can write a test for a class, depends on whether you can
isolate that class. And whether you can isolate the class, is a
function of the code structure, not of what the code does.  Ability to
write a test in isolation is not a function of trying harder, it is
really not possible to write the test if the code is not structured
properly. Here we are not talking about algorithmic functions as in
your example which really are leaves of the execution tree, but we are
talking about large scale applications.
So when I say that the testability is a function of code structure
rather then what the code does, this is what I mean.

-- misko

On Sat, Sep 17, 2011 at 7:24 PM, Karl Lieberherr <lieber at ccs.neu.edu> wrote:
>
> Hi Misko:
>
> thank you for your reply and for asking around.
>
> Did you agree with my counter example to one of your claims about testing?
>
> -- Karl
>
> On Fri, Sep 16, 2011 at 11:59 PM, Misko Hevery <misko at hevery.com> wrote:
> > Hi Karl,
> > It is an honor to receive an email from the birth-place of LoD. I have sent
> > your email to some folks at google, but unfortunately none of them seem to
> > be the right people, so it seems to be a bit of dead end on my side. sorry.
> > :-(
> > -- Misko
> >
> > On Fri, Sep 16, 2011 at 7:18 AM, Karl Lieberherr <lieber at ccs.neu.edu> wrote:
> >>
> >> Hi Misko:
> >>
> >> thank you for popularizing the Law of Demeter in your very informative
> >> talks about clean code over the last few years. My PhD student Ian
> >> Holland originally formulated the Law of Demeter and we published the
> >> first papers.
> >>
> >> =========================
> >> Taken literally, I don't agree with one of your statements:
> >>
> >> Whether code is easy to test is a function of the structure of the
> >> code and not a function of what the code does.
> >>
> >> Input: x in [0,1], c in [0,1].
> >> Output: y in [0,1] with property: x*y + (1-x)*(1-y^2) >= c
> >> or "no such y exists".
> >>
> >> Program:
> >> If c > 1/2 (sqrt(5)-1) then output("no such y exists")
> >> else output ("y=", min(x/(2-2 x),1))
> >>
> >> To properly test this program, it is not enough to look
> >> at the structure of the code but it really requires to understand
> >> what the code does.
> >> =========================
> >>
> >> Over the last few years we have developed a tool for developing
> >> software for computational problems using an exciting game. If you
> >> want software for problem Q, you define a playground for Q which you
> >> advertise to software developers. They solve Q by writing an avatar
> >> that plays in the playground for Q against the avatars of other
> >> developers. The winning avatar in the playground contains the best
> >> algorithms among the given set of avatars.
> >>
> >> We use this game
> >> http://www.ccs.neu.edu/home/lieber/evergreen/specker/scg-home.html
> >> to encourage our students to write clean, testable code because
> >> otherwise they cannot easily improve their avatar and they fall behind
> >> in the game.
> >>
> >> I think this game might also be of interest to Google, for example to
> >> solve all kinds of optimization problems? It is also good for
> >> crowdsourcing the development of a knowledge base about claims that
> >> can be computationally refuted and defended, e.g., is there Global
> >> Warming.
> >>
> >> Please can you refer me to the right person at Google who might be
> >> interested in the Scientific Community Game.
> >>
> >> Thank you,
> >> -- Karl
> >
> >



More information about the Cs5500 mailing list