Hi Today I typed something funny in the interactive interpreter:
while: File "<stdin>", line 1 while: ^ SyntaxError: invalid syntax
it got me wondering, wouldn't it be nice if while: ... behaved as: while True: ... Since they appeared, I started using "while True:" instead of "while 1:" for this common idiom. I find it reveals the intention better, but I don't like the typing. Opinions? cheers,
On Wednesday 20 July 2005 13:13, Martin Blais wrote:
it got me wondering, wouldn't it be nice if
while: ...
behaved as:
while True: ...
-1
I don't expect if: or for: to mean anything, so why
should while: ? I don't see any advantages to it (saving
5 keypresses? please...)
Anthony
--
Anthony Baxter
El mié, 20-07-2005 a las 13:26 +1000, Anthony Baxter escribió:
On Wednesday 20 July 2005 13:13, Martin Blais wrote:
it got me wondering, wouldn't it be nice if
while: ...
behaved as:
while True: ...
-1
I don't expect if: or for: to mean anything, so why should while: ? I don't see any advantages to it (saving 5 keypresses? please...)
maybe a new idiom forever: ... is in order? (perhaps it would be better to call it "always:" or "until_break") (this message is a bit tongue-in-cheek) =)
Anthony
--
Manuel Amador
On 7/20/05, Martin Blais
it got me wondering, wouldn't it be nice if
while: ...
behaved as:
while True:
-1 Explicit is better than implicit. Regards, . Facundo Blog: http://www.taniquetil.com.ar/plog/ PyAr: http://www.python.org/ar/
On 7/20/05, Facundo Batista
On 7/20/05, Martin Blais
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,
On 7/20/05, Martin Blais
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?
See your point. But, for me (spanish speaker), if I read a ``while:``, I think, "while what?". . Facundo Blog: http://www.taniquetil.com.ar/plog/ PyAr: http://www.python.org/ar/
В Срд, 20/07/2005 в 21:58 -0300, Facundo Batista пишет:
On 7/20/05, Martin Blais
wrote: 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?
See your point.
But, for me (spanish speaker), if I read a ``while:``, I think, "while what?".
The same here, so -1 for while: Ruslan
On Thursday 2005-07-21 01:22, Martin Blais wrote:
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).
To me, the "least unexpected thing" for "while:" to do is to raise a syntax error. The principle of least surprise doesn't mean that for every sequence of tokens you should pick the least surprising thing it could do, and give it that definition. (That's what they do in C++, except for the bit about picking the least surprising semantics.) -- g
participants (6)
-
Anthony Baxter
-
Facundo Batista
-
Gareth McCaughan
-
Manuel Amador
-
Martin Blais
-
Ruslan Spivak