[Python-ideas] if-statement in for-loop

Paul Moore p.f.moore at gmail.com
Wed Oct 5 03:31:49 EDT 2016


On 5 October 2016 at 05:09, Ken Kundert <python-ideas at shalmirane.com> wrote:
> On Wed, Oct 05, 2016 at 03:07:42AM +1100, Steven D'Aprano wrote:
>>
>> Extra newlines are cheap. Writing
>>
>
> The cost is paid in newlines *and* extra levels of indentation.

No extra indentation if you ise "if not condition: continue" or
refactor the condition into a custom iterable. Both of which have
already been mentioned here as ways of achieving the desired result
without a language change.

> Why isn't it the programmer that is writing the code the best person to decide
> what is best?

Because the programmer writing the code isn't going to write and
maintain the changes to the CPython/Jython/PyPy codebases, write the
tests and documentation, support the questions that come from other
users, etc...?

More seriously, that argument could apply to *any* proposal. "Let the
user decide whether to use the feature or not, and just add it".
However, not all features get added precisely because someone has to
make a cost/benefit judgement on any proposal and the people who do
that are the CPython core devs. Discussion on this list is about
thrashing out convincing arguments that will persuade the core devs -
which is one of the reasons a lot of the core devs hang out here, to
provide a sounding board on whether arguments are convincing or not.

"Make the feature available and let the user decide if they want to
use it" isn't a convincing argument. At best it could be a small part
of a larger argument. It's countered by "does it make the language
harder to teach having multiple ways of doing things?", "what about
edge cases?" (in this case, trailing elses have been mentioned), "is
there a well-known and easy workaround?", "no other languages (apart
from Perl) seem to have this feature", ... and those issues need to be
addressed in a full proposal.

Paul


More information about the Python-ideas mailing list