why only one ":" in a line ... ?

Jere Kahanpaa kahanpaa at gstar.astro.helsinki.fi
Mon Aug 19 20:09:16 CEST 2002


Hi.

Andreas Leitgeb <Andreas.Leitgeb at siemens.at> wrote:
> My motivation for this question:
> During porting some old c-code, that contained lots of simple blocks like:
>   while (cond1) { stmt; if (cond2) break; }
> these lines were simple enough, that their one-lined'ness did not
> obfuscate it, but rather made it more readable.

> In Python however, each of these phrases need to get expanded to  
>   *three* lines, because even the small "stmt" needs it's own line!
>   (I can't put it after the "while" nor in front of the "if")

Wouldn't this do the same think in one Pythonic line:

while (COND1 and not COND2): stmt

Of course, this is not the same in detail: if COND2 is false from the start, the 
Python version fails while the C version loops at least once. Wether this is good 
or bad depends on your real code.

>  I don't want to discuss the worth of putting something in one line,
>  what I could also break up into more lines. It's just that for
>  some blocks, I as a programmer would prefer them in one line.

> e.g.:
>  if 0<n<10: for i in range(n): print i
> this is invalid.
> but why is it invalid ?

Because it is less easy to read than the valid (2-line) version. At least IMO that 
is. 

*SNIP* 
several special case cut

As youself pointed out, allowing 'more stuff in one line' leads to complexity and 
thus is goes against the KISS (Keep It Simple, Stupid) rule.

> So what's so bad about "putting stuff in one line" ?

It's a matter of taste. If you don't like the limits of Python, use Perl.

Jere
-- 
It's hard to think outside the box when you ARE the box.
                            - unknown, alt.religion.kibology 



More information about the Python-list mailing list