[Python-ideas] More classical for-loop
Mikhail V
mikhailwas at gmail.com
Sat Feb 18 21:58:56 EST 2017
On 19 February 2017 at 01:01, Erik <python at lucidity.plus.com> wrote:
> On 18/02/17 19:35, Mikhail V wrote:
>>
>> You mean what my proposal would bring
>> technically better than e.g.:
>>
>> for i,e in enumerate(Seq)
>>
>> Well, nothing, and I will simply use it,
>> with only difference it could be:
>>
>> for i,e over enumerate(Seq)
>>
>> In this case only space holes will be
>> smoothed out, so pure optical fix.
>
>
> But you also make the language's structure not make sense. For good or bad,
> English is the language that the keywords are written in so it makes sense
> for the Python language constructs to follow English constructs.
>
> An iterable in Python (something that can be the target of a 'for' loop) is
> a collection of objects (whether they represent a sequence of integers, a
> set of unique values, a list of random things, whatever).
>
> It is valid English to say "for each object in my collection, I will do the
> following:".
>
> It is not valid English to say "for each object over my collection, I will
> do the following:".
>
> In that respect, "in" is the correct keyword for Python to use. In the
> physical world, if the "collection" is some coins in your pocket, would you
> say "for each coin over my pocket, I will take it out and look at it"?
That is very fair point and very interesting topic.
There is even such classification of languages,
how 'natural' are they, and Python is definitely a more
natural language. At the same time it is sort of unique selling
point of the language, for those who look at it or start to read
the code for the first time.
Right after that however, pure physics comes in play.
So memorizing a visual pattern happens in some minutes
of active reading, but further reading lasts "till final victory".
Obviously proposing something like "amore" as a keyword
would cause only laughter.
Nevertherless, the language that uses more
reading-effective patterns, in physical sense,
will be superior to the language that uses "meaningful"
words but which are optically bad,e.g. "all" or "through".
And with all respect, "in" happens to be one.
> Soon someone else will propose another syntax
> for a different subset. This is why people are
> talking about the "burden" of learning these
> extra syntaxes. Rather than 10 different syntaxes
> for 10 different subsets, why not just learn
> the one syntax for the general case?
I suppose you mean this pair:
for i,e in enumerate(Seq):
for e in Seq:
and conditional
if e in Seq:
Certainly "over" will not suit in the last example,
that is true.
But probably swap "in" to "amore" :-)
I will be totally ok with it, and it is a good visual
pattern. Also it is international, so non-native
speakers will learn easier, and +1 to the selling point.
None of my words cancel the 'burden', and the
'burden' is tremendous I can imagine. So
obviously it is not easy. However most of the
burden is not in the word learning .
Mikhail
More information about the Python-ideas
mailing list