[Python-ideas] Is this PEP-able? for X in ListY while conditionZ:

Shane Green shane at umbrellacode.com
Wed Jun 26 07:44:11 CEST 2013


On Jun 25, 2013, at 6:40 PM, Steven D'Aprano <steve at pearwood.info> wrote:

> On 26/06/13 05:45, Shane Green wrote:
>> Even though they declare “break” is bad, they don’t actually mean break is bad.
> 
> I'm pretty sure they mean exactly what they say. Why else would they say it? The coding standard in question is as clear as day:
> 
They say “break” because its typical usage violates, or simply makes it very easy to violate, rules they want to abide by.  It was taboo before Python really even came about.  I guess I’m a lot closer to questioning authority than I am to believing educators are psychic :-)

> 
> 
>> It’s when it’s used to control the flow–as in causing flow to skip sections of code, etc.–of an application that it’s primarily considered bad.
> 
> I don't understand what this even means. 


Yeah, that was a shite explanation; sorry about that.  Luckily, I realized what I meant while writing the last point: don’t loops have their own scope in C?  Well, I think much of the backlash may come from (poorly) applied break statements altering the with block scope, it can alter variable declaration, initialization, etc.  


> I don't understand what this even means. When is break anything other than a flow control statement? 

It’s usage in [x for x in l if x else break] doesn’t actually determine which code gets run, *only* how many times or, more importantly, the number of items in the output.  


But these are honestly wild ass guesses, to be honest.  There is one thing I can say for certain is that anyone who says “break” is always bad, is wrong.  Most professors are perfectly happy accepting code that leverages features the generally tell kids not to use, as long as it’s not use rampantly or incorrectly and the student as a solid grasp of it and can clearly articulate the reason for using it.  







On Jun 25, 2013, at 6:40 PM, Steven D'Aprano <steve at pearwood.info> wrote:

> [quote]
> Using break and continue is not allowed in any of your code for this class. Using these statements damages the readability of your code. Readability is a quality necessary for easy code maintenance.
> [end quote]
> 
> http://www.csee.umbc.edu/courses/201/spring10/standards.shtml
> 
> 
> This is a foolish standard, since using break and continue actually improves readability over the alternatives such as:
> 
> skip = False
> for x in seq:
>    if skip:
>        pass
>    elif cond(x):
>        skip = True
>    else:
>        do_this()
>        do_that()
> 
> 
> (or worse!) instead of:
> 
> for x in seq:
>    if cond(x):
>        break
>    do_this()
>    do_that()
> 
> 
> 
> But Python's syntax shouldn't be driven by educators with dumb ideas.
> 
> 
>> It’s when it’s used to control the flow–as in causing flow to skip sections of code, etc.–of an application that it’s primarily considered bad.
> 
> I don't understand what this even means. When is break anything other than a flow control statement? And what difference does it make whether it is used in an "application", "script", "library", or something else?
> 
> 
> 
> -- 
> Steven
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130625/b9994c69/attachment.html>


More information about the Python-ideas mailing list