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

Steven D'Aprano steve at pearwood.info
Wed Jun 26 03:40:40 CEST 2013


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:

[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


More information about the Python-ideas mailing list