loop, breakif, skip
These 4 proposals are somewhat inter-dependent, so I include them in a single message. They are simple ideas, childish almost. Think of non-programmers writing simple scripts, and children learning basic coding in grade school. Hope I'm not wasting your time with nonsense. (I'm not an advanced programmer, so can't be sure.) ------------ Proposal 1 Abolish 'continue' in loops, and use 'skip' instead. In normal English 'continue' means 'carry on at the next line'. In most programming languages 'continue' means 'jump back UP the page to the start of this loop'. This is OK for programmers accustomed to C, but I find it very counter-intuitive, even though i know it means 'continue with the next iteration'. On the other hand, 'skip', meaning 'skip the rest of this iteration', feels more intuitive to me. 'continue' is too long, 'skip' is short. One new keyword. Breaks existing code. ------------ Proposal 2 an alternative to PEP-315, and a simpler way to write while loops of various flavours. part A 'loop:' is exactly equivalent to 'while True:' part B (1) '*breakif <condition>' is exactly equivalent to 'if <condition>: break' (2) '*skipif <condition>' is exactly equivalent to 'if <condition>: skip' (assuming 'skip' replaces 'continue') * is to make the word easier to find by human eye. would some other character do it better? 2a and 2b together allow while loops to optionally look something like this: loop: <statements> *breakif <condition> <statements> *skipif <condition> <statements> *breakif and *skipif can be used in for loops too, of course. 3 new keywords. Existing code would not be affected, unless it was already using loop, *breakif or *skipif as names. ------------ Proposal 3 Mainly for young students learning to program. the keyword 'loop' can be placed in front of the keyword 'while' the keyword 'loop' can be placed in front of the keyword 'for' without changing the meaning of 'while' or 'for'. Looks like this loop while <condition>: <statements> loop for <iteration expression>: <statements> Allows beginner students the satisfaction of thinking that every kind of loop begins with the word 'loop', which also makes learning a little easier. (Later they will learn that 'loop' can be left out.) Existing code would not be affected. ------------ Proposal 4 If 'continue' is not used in loops, it can have a more meaningful role in switch/case blocks. 'continue' in a Python switch block would have a meaning opposite to that of 'break' in a C switch block, allowing you to do 'fall-through'. Here 'continue' would have its intuitive meaning of 'carry on at the next line'. switch <expression>: case <values>: <statements> [continue] case <values>: <statements> [continue] case <values>: <statements> Existing code would not be affected, as switch/case is not implemented yet. ------------ Jim Hill
Jim Hill wrote:
Think of non-programmers writing simple scripts, and children learning basic coding in grade school.
Abolish 'continue' in loops, and use 'skip' instead.
I wouldn't recommend teaching beginning programmers about continue at all, whatever it's called. It's an unneccessary complication when learning the fundamentals.
'loop:' is exactly equivalent to 'while True:'
'*breakif <condition>' '*skipif <condition>'
These just look ugly and unpythonic.
the keyword 'loop' can be placed in front of the keyword 'while' the keyword 'loop' can be placed in front of the keyword 'for'
'Loop' is a piece of programming jargon, not something that would occur readily to someone thinking in everyday terms. Python's way of phrasing its loops is closer to natural English, therefore, one would expect, easier for beginning programmers to get the meaning of.
Allows beginner students the satisfaction of thinking that every kind of loop begins with the word 'loop',
All two of them? I don't think that's a big enough burden on the memory to be worth introducing Another Way To Do It.
'continue' in a Python switch block would have a meaning opposite to that of 'break' in a C switch block, allowing you to do 'fall-through'.
I don't think that's any more intuitive than its current meaning. The word 'continue' on its own doesn't really say anything at all about *what* to continue with, except in a context where you're stopped in some way, which is not the case here. So whatever meaning is chosen, it's something that has to be learned. -- Greg
participants (2)
-
Greg Ewing
-
Jim Hill