[Python-Dev] while:

Martin Blais martin.blais at gmail.com
Thu Jul 21 02:22:15 CEST 2005


On 7/20/05, Facundo Batista <facundobatista at gmail.com> wrote:
> On 7/20/05, Martin Blais <martin.blais at gmail.com> wrote:
> 
> > it got me wondering, wouldn't it be nice if
> >
> >    while:
> >       ...
> >
> > behaved as:
> >
> >    while True:
> 
> -1
> 
> Explicit is better than implicit.

Well, maybe you're reading a bit too litterally into that statement. 
To me the expression is very explicitly absent :-)    More seriously,
reading into these rules too literally leads to funny places: I could
ask why at the end of functions there is an implicit "return None"
(I'm not expecting an answer).  Explicit better than implicit?

The Rule of Least Surprise says to me that "while:" would do the least
unexpected thing.  There are only two possibilities: the test is
implicitly false, in which case "while:" would make no sense (i.e. the
block would be ignored).  Therefore the other only sensible case is
that the test is implicitly true, which can be useful (and also
happens to be a very common idiom).

It's not so much about saving typing characters: it's just low-hanging
fruit that simplifies the language a little bit (well, "simplify" is
arguable though, if you consider the grammar it makes it a tiny bit
more complex, but that is usually not the programmer's point-of-view).

Bah, whatever, +0

cheers,


More information about the Python-Dev mailing list