Thoughts on PEP315

T

Tim Rowe

This would be a nightmare for the parser - until it finds the colon or
end-of-line (or semicolon perhaps) it simply wouldn't know which case
it was dealing with.

But if this is bad for the parser, just think what it would do to
users! - forgetting a trailing semicolon shouldn't result in a
statement which is legal yet with a significantly different meaning.

That's why I don't like it in Perl and Ruby -- I can tell it's hard
for the parser because so few syntax highlighters get it right!

Maybe I'm getting twitchy about nothing -- after all, indentation
being significant brough back unhappy memories of FORTRAN, but Python
makes it work...
 
S

Stephen Horne

I think someone once suggested "and while" instead of a plain while:

do:
...
and while condition:
...

This reads quite nicely IMO.

Hmmm.

It certainly has all the advantages I claimed for 'break if'. At the
moment my mental parser is choking on it - but I can't give a good
reason why. Probably it's just odd seeing 'and' at the start of a
line, I suspect.
 
S

Stephen Horne

That's why I don't like it in Perl and Ruby -- I can tell it's hard
for the parser because so few syntax highlighters get it right!

Maybe I'm getting twitchy about nothing -- after all, indentation
being significant brough back unhappy memories of FORTRAN, but Python
makes it work...

That was basically a fluked typo - I meant the missing the trailing
colon at the end of the 'break if ...' line, but of couse a semicolon
added/lost semicolon in the wrong place can be just as bad.

I don't think this would hurt Python the same way, though, as 'if'
cannot follow after a statement on the same line for (presumably to
ensure that the indentation makes sense)...
File "<stdin>", line 1
break ; if 1 :
^
SyntaxError: invalid syntax


So a 'break if ... :' cannot accidentally metamorphose into a 'break;
if ... :'.
 
N

Neil Padgen

Stephen> So a 'break if ... :' cannot accidentally metamorphose
Stephen> into a 'break; if ... :'.

It can if you press return at the wrong place:

while True:
blah ; blah ; blah
break
if condition:
blah ; blah ; blah

This would be perfectly legal if the new-style while loop were in
another loop.

-- Neil
 
S

Stephen Horne

Stephen> So a 'break if ... :' cannot accidentally metamorphose
Stephen> into a 'break; if ... :'.

It can if you press return at the wrong place:

while True:
blah ; blah ; blah
break
if condition:
blah ; blah ; blah

This would be perfectly legal if the new-style while loop were in
another loop.

I don't think this is a serious problem. It's hard to miss the fact
that the 'break' and the 'if' are on different lines.

You might just as well claim that...

print "Hello World"

....is bad syntax because...

print
"Hello World"

....is legal but (particularly when not run from the command line)
different.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top