Re: Conditional iteration



My comments below.

Kind regards,
@


Carl Banks wrote:

at wrote:
Well, all I can say that for me as a user it would make sense...

Which is, like, step one out of a hundred for getting a syntax change
into the language.

Curiosity: in what sense is it redundant?

It creates syntactical support for two different ways to do something.
If your plan were adopted, then we'd have two different spellings for
the same thing:

for i in a:
if i != 0:
use(i)

for i in a if i != 0:
use(i)

With the current Python syntax, I can create for every two lines of code a
dozen alternative implementations:

# example 1
a = {}
a['b'] = 'c'

versus:
a = {'b': 'c'}


# example 2
l = []
for l in some_list:
if some_condition:
l.append(l)

versus:
l = []
for x in some_list:
if some_condition:
l = l + [x]

or:
l = [x for x in some_list if some_condition]

(the beautiful one)

So your argument doesn't mean much I would say!


Now, redundant syntax isn't a deal breaker by itself. You have to ask
what is buys you. In this case, all it does is save you a single level
of indentation--that's it. There's no performance benefit. It doesn't
simplify logic. It doesn't make the code any more readable of clear.
It's only a minor improvement in conciseness. It hardly saves any
typing (unless you indent by hand). Even its one clear benefit, saving
indentation, is something you can already get with "if not x:
continue".


Well there is a clear performance benefit, or more precisely a productivity
benefit. And -please- do not underestimate this for a language like Python,
which has many supporters due to its perceived and high productivity and
challenged on this point by languages like Ruby.

'for x in some_list if some_condition:'

is psychological very strong, because the brain will most likely treat the
in the same way as :

for every apple in the fruitbasket take one if green


Basically upon reading this first line you know exactly to what list of
items your next section of code applies.

But again everything is a matter of taste and I assume that's why the change
control body is put into the hand of one person.



Considering how little this syntax change buys, it really doesn't make
a lot of sense for a language that places high emphasis on avoiding
redundancy.


All solution/workarounds I have seen so far involve creation of new lists
(subsets) adding to more processing/computation/memory usage. Redundant
suggests that you know alternatives that don't do that.

Does Guido ever change his mind?

Yes, but I guarantee "it makes sense for me" isn't going to convince
him. By the way, I'd suggest when posting to comp.lang.python and/or
python-list in the future, you put your replies beneath the quoted text
for the benefit of any future readers (not to mention present readers).

I hope this this thread will support the "it makes sense for me" with
arguments. Again it is not my intention to fight windmills, but to see if
there are strong arguments against it on one hand and if there supporters
on the other hand.



Carl Banks

.



Relevant Pages

  • Re: Implicit object constructor misinterpretation
    ... specified for the language that is being parsed. ... sub-set of the syntax for object literals. ... document that will teach anyone how to program with javascript. ... Consider the issue in your OP; you can speculate about "broken switch-case" or "not a constructor but a block of statements", but an examination of the spec shows that the observed behaviour corresponds with the specified behaviour, and explains the specified behaviour. ...
    (comp.lang.javascript)
  • Re: What is this code doing?
    ... Using the same syntax for most statements helps make the ... add, ebx); ... Instruction composition readability is another reason ... Jim Neil's Terse language). ...
    (alt.lang.asm)
  • Re: New bytecode assembly language to play with
    ... language that looks familiar, something I could probably figure out quite ... about a bit of superficial syntax here. ... The wheel has been reinvented several times. ... one that introduces new functionality, i.e. it's not just another way ...
    (comp.lang.misc)
  • Re: Working on new language
    ... I'll make sure to put some warts in the language:) ... syntax to me is misguided. ... So apart from the "so" keyword mentioned below I require ... It would be possible to separate arguments with commas, but the opens ...
    (comp.lang.misc)
  • Re: 10 ten things any good programmer can/has done?
    ... To quote Shriram Krishnamurthi, syntax ... > stress issues other than the surface syntax of some programming language. ... It means that more time has to be spend teaching the ...
    (comp.programming)