Why ELIF?

Mensanator mensanator at aol.com
Mon Oct 12 01:12:50 CEST 2009


On Oct 11, 5:05�pm, Carl Banks <pavlovevide... at gmail.com> wrote:
> On Oct 11, 7:10�am, Grant Edwards <inva... at invalid.invalid> wrote:
>
> > On 2009-10-11, metal <metal... at gmail.com> wrote:
>
> > > I wonder the reason for ELIF. it's not aligned with IF, make code ugly
>
> > It most certainly is aligned with IF:
>
> > � if cond1:
> > � � � do this
> > � elif cond2:
> > � � � do that
> > � else:
> > � � � do the other
>
> > The "if" "elif" and "else" are all aligned in all of the code
> > I've ever seen.
>
> The condition in the elif clause is two columns to the right of the
> condition in the if clause.

Why does that matter? Isn't whitespace only
significant at the start of a line?

>
> It's a silly thing to worry about, in fact the slight visual
> distinctness of it probably helps readability.

It doesn't, but you're right, it's silly to
worry about.

> �Some people do get
> finicky about columns and try to line things up all the time. �

But you can do it if you really want to:

a          =  1
if      a  >  5:
  print a
elif    a  > 10:
  print a  /  3
else:
  print 'error'

>It's
> frustrating, wasteful, and ultimately hopeless, and sometimes
> deceptive (lining things up can suggest relationships where none
> exists) so I make it a point not to do it, however prettier it'll make
> those two lines.

The above example is of dubious value. Where I
use it is places like

ONE   = gmpy.mpz( 1)
TWO   = gmpy.mpz( 2)
THREE = gmpy.mpz( 3)
TEN   = gmpy.mpz(10)

>
> Carl Banks




More information about the Python-list mailing list