Re: Clause readability

2008-09-08 Thread Richard A. O'Keefe

From: John Pane <[EMAIL PROTECTED]>
Part of an experiment I did during my Ph.D. research looked at the
readability of unless clauses at the beginning or end of a statement.
Users were significantly more accurate when the clause was at the end.
See:
http://www.cs.cmu.edu/~pane/VL2000.html


It's not clear that this actually addresses Russel Winder's question
about Groovy.  Let me explain why (maybe) not.

1.  That research was about designing a programming language for
children, and the experimental subjects were therefore
>> non-programmers <<.  Some of the subjects said they had
programmed, but the paper gives no indication of how much,
to what degree, or in what language.

One expects that most of the people dealing with Groovy will
have had previous experience with programming and will know
that it _really_ isn't English.

2.  English and many other languages exploit a feature called  
'ellipsis'.

For example,
count the cars from Georgia and Louisana
is a CORRECT way to ask for
#{c | c is a car and (c is from Georgia OR c is from Lousiana}
in English because it is an elliptical form of
count the cars from Georgia and [
count the cars from] Louisiana.
Unfortunately, it's ambiguous, and relies on human intelligence
to figure out where the gaps are and how to fill them.

The study used ENGLISH WORDS for the logical operators
AND, OR, NOT.  It is far from obvious that such confusion
would carry over to symbols such as &&, ||, !.  (It's also
far from obvious that it wouldn't.)

3.  On the specific topic of placement of unless, the paper says
"The participants performed significantly better with the
 Unless clause at the end than they did with the Unless
 clause earlier in the statement.
 HOWEVER, given that [Unless didn't actually help much],
 THE IMPORTANCE OF THIS IS QUESTIONABLE."  (My emphasis.)

I don't mean to slight the research.  It's important that research
like this be done, and the choice of participants &c were all
appropriate to the questions the project was designed to answer,
namely "what would be good for a children's language".  ALL that
I am saying here is that it's not clear that the results are
relevant to Groovy.  To the extent that they are, then the
answer would be "people will prefer putting unless at the end,
but it won't improve their programs."

I note that there is just a trace of this in Ada, where the
loop exit statement is
exit [when Expression];
So there is another alternative in the middle:
allow [if/unless Expression]
on control transfers such as method return and
loop exit *only*.



Re: Clause readability

2008-09-08 Thread Frank Wales

John Pane wrote:
Part of an experiment I did during my Ph.D. research looked at the  
readability of unless clauses at the beginning or end of a statement.  
Users were significantly more accurate when the clause was at the end.  


This is consistent with how I use 'unless' clauses in my own code.

I often find it more readable to have something like:

  explode unless fine && dandy;

rather than either of:

  unless (fine && dandy) {
explode;
  }

or

  if (not (fine && dandy)) {
explode;
  }

Of course, when a simple explosion can't rectify the situation,
I will sometimes use the more usual statement form:

  unless (the_gangs_all_here) {
scrub_the_mission;
pack_up_the_tent;
cancel_all_my_appointments(Miss_Jones);

return;
  }

But I will think carefully in such cases to make sure that
a straightforward 'if' mightn't be clearer, since it's
by far the more common idiom for shepherding the reader's
attention around optional code.

I do tend to restrict my use of 'if' or 'unless' as
trailing statement modifiers to those times when I
want to draw the reader's eyes to the statement being
modified, rather than to the exceptional condition being
tested.  It's a way of shifting emphasis away from the
definition of the governing condition, and it's clearly a
judgement call when to do this that reasonable programmers
might disagree about over cocktails and pizza.

However, I'm quite happy to assert that the potential
readability of a language is mildly enhanced by the options
to use 'unless' and trailing modifiers, since they take
nothing away from the language, no-one is compelled to use
them, and my cynicism about programmer skill isn't yet so great
that I feel the need to deprive good programmers of useful
tools for expressive nuance that poor programmers might find
confusing.

There is arguably a case for disallowing 'else' with 'unless'
(which would also be a side-effect of having 'unless' *only*
as a trailing modifier), since otherwise a spurious desire for
lexical symmetry might encourage you to allow constructs such as:

  unless (we_can) {
say_we_cannot
  }
  else {
nobody_understands_when_this_clause_runs
  }

which I don't believe I've ever used in any language that allows
it, mainly because it's just an inverted if...else... (whereas
an 'unless' clause is the 'else...' without the 'if...').
--
Frank Wales [EMAIL PROTECTED]


Clause readability

2008-09-08 Thread C.Douce
(below message was bounced to me due without being sent to the list due
to a  membership error that I have since corrected)



From: John Pane <[EMAIL PROTECTED]>
To: ppig-discuss-list@open.ac.uk

Russel,

Part of an experiment I did during my Ph.D. research looked at the  
readability of unless clauses at the beginning or end of a statement.  
Users were significantly more accurate when the clause was at the end.  
See:
http://www.cs.cmu.edu/~pane/VL2000.html

John



On Sep 6, 2008, at 2:07 AM, Russel Winder wrote:

> There is currently a big debate in the Groovy mailing list about
> introducing:
>
>if 
> and
>unless 
>
> constructs into the language.  Anyone familiar with Perl or Ruby will
> have come across this "condition after expression" construct.  In Perl
> and Ruby these are additional selection constructs to the ones found  
> in
> Fortran, Algol68, Pascal, C, C++, Java, Python, Groovy, and of course
> Perl and Ruby:
>
>   if  
> and
>   if   else 
>
> though in some languages the expressions are statement, but that is
> technical detail.
>
> As you can image the debate is between the yes and no camp :-)  Some  
> of
> the arguments are about consistency and minimalism which are fairly
> objective ones, but many of the arguments are about readability and
> comprehension, which is of course where PPIG comes in.  Many of the
> arguments people are putting forward on readability and comprehension
> are based simply on personal experience and prejudice.  What I would
> like to do is to introduce an element of science to the debate.  For
> this I need experimental data and input from psychology about
> readability and comprehensibility.
>
> So does anyone know of any work on readability and comprehensibility  
> of
> these two varieties of selection structure.
>
> Thanks.
>
> -- 
> Russel.
> 
> Dr Russel Winder   t: +44 20 7585 2200
> 41 Buckmaster Road   m: +44 7770 465 077
> London SW11 1EN, UK  w: http://www.russel.org.uk/