PEP308: a call for usability studies (was Re: Update to PEP308: if-then-else expression)

Anders J. Munch andersjm at dancontrol.dk
Thu Feb 13 07:17:53 EST 2003


"Carel Fellinger" <carel.fellinger at chello.nl> wrote:
> 
> 1)   a = 1
> 
> 2)   if a == 1:
>         b = 2
>      else:
>         b = 3
> 
> 3)   b = 2 if a==1 else 3
> 
> 4)   b = (if a==1: 2 else: 3)
> 
[...]
> All three prefered 2, had no problems understanding 3, but it took
> them quit some time to understand 4.  Even more remarkably, as they
> claimed that having seen snippets 2 and 3 they already knew the anwser.
> 
> 
> Not quite what you would have expected, hm.  

No?  (2) is preferred because GvR did a good job designing Python.
(3) is understood through familiarity with language.  It reads like a
natural language sentence, which is nice but won't scale to more
complex expressions.  (4) is intended to be understood through
familiarity with Python, however your test subjects are very little
familiar with Python.

I wonder how they would resolve the ambiguity in
  a = 5
  b = a + 1 if a==1 else 3

I'd expect that, reading it as a statement in natural language, they
would come up with b==3 and the possibility of a different
interpretation where b==8 would not even cross their minds.

- Anders






More information about the Python-list mailing list