Conditional Expressions don't solve the problem

Christopher A. Craig com-nospam at ccraig.org
Thu Oct 18 10:10:19 EDT 2001


salemail at dial.pipex.com (Kevin D) writes:

> Can I assume that's IYHO ? Please elucidate on what, exactly, numbs
> your mind about them. I've tried to reason out what I thought were the
> issues that cause this thread to appear periodically (modulo "it isn't
> like C") and suggest syntax that fixes those problems.
> 
> Can we at least agree that the issues I listed _are_ problems ? If
> not, please give reasons.
> 

I do appreciate your not trying to make Python like C.  I will try to qualify
my reservations.  Here is your original suggestion (just because I don't like
replying to it without it being quoted):

] Something like:
] 
]  while foo != terminating_condition; given foo = some_long_expression:
]      body_of_loop()
]  
]  or maybe "where":
]  
]  while foo != terminating_condition; where foo = some_long_expression:
]      body_of_loop()
]  
]  This would extend to 'if'/'elif':
]  
]  if m is not None; where m = compiled_re.match(inputline):
]      stuff(m)
]  elif m is not None; where m = compiled_re2.match(inputline):
]      otherstuff(m)

My problems with it:
1) Foo is assigned after foo is referenced.  This is ugly and requires a
   second pass by the compiler which currently no Python construct does.

2) This syntax is complicated.  It seems un-Pythonic to me to have more than
   one statement per line.

> [ my stuff about do: until loops ]
> I don't see what _problem_ this is addressing. You're just
> substituting words. I was actually trying to _identify readability
> issues_ with this construct and fix them.

But even your suggestion doesn't really contribute that much.

while <condition>; where <statement>:
  <body>

could also be expressed as

while 1:
  <statement>
  if not <condition>: break
  <body>


The problem, as you pointed out, is that the second form is ugly.  It is not
really a while loop, yet uses the keywords of one.  Thus in addition to the
'while' form in Python, we frequently see a special 'while 1: if not' form.  I
see presenting it as

loop:
  <statement>
  until <condition>
  <body>

as being more intuitive and still keeping one statement per line.  (It also
generalizes to  

loop: 
  <statements>
  until <condition>
  <statements>

for when you need multiple statements in your initialization.  That said, I'm
not sure there is sufficient motivation to add two keywords just for sugar.

> > Additionally I think that the present system is not that hard to adapt to.
> 
> Remembering to prefix all your string variables with '$' and all your
> integer variables with '%' isn't "hard to adapt to". Plenty of BASIC
> newbies did. That doesn't mean that there aren't better ways of doing
> it :)

-1 me.  That said, many of the posts in this thread have been advocating
change, not because the change is better, but because Python doesn't fit
their method of writing programs.  I personnally don't think that your change
adds enough functionality to justify putting the usage of a variable before
its assignment, but my opinion doesn't count for that much, so take that for
what it's worth.



-- 
Christopher A. Craig <com-nospam at ccraig.org>




More information about the Python-list mailing list