[Python-ideas] Simpler syntax for basic iterations

Ben Finney ben+python at benfinney.id.au
Tue Oct 13 21:49:39 CEST 2015


"Sven R. Kunze" <srkunze at mail.de> writes:

> On 13.10.2015 00:21, Ben Finney wrote:
> > Since this is quite clearly expressed in existing Python syntax with::
> >
> >      for __ in range(3):
> >          forward(100)
> >          turn_left(120)
> >
> > the single use case doesn't IMO argue for benefit sufficient to overcome
> > the enormous burden of new syntax.
>
> I still like instead of the cryptic __ or _
>
> for each in range(3):
>     dosomething
>
> To me, that reads like a normal English statement.

What you cite as an advantage is exactly why I'd advise against it. Your
example would lead me to ask “Is this a mistake? ‘each’ is a normal
name, why isn't it being used?”

Whereas ‘__’ is not a normal name, and like other unusual names in
Python should lead the reader to say “Okay, obviously the person writing
this had something odd in mind. I'd better find out what.” That is more
likely to teach about the ‘__’ convention, than to be seen as a mistake
by experienced programmers.

-- 
 \        “You don't change the world by placidly finding your bliss — |
  `\        you do it by focusing your discontent in productive ways.” |
_o__)                                       —Paul Z. Myers, 2011-08-31 |
Ben Finney



More information about the Python-ideas mailing list