Code basics

Joshua Macy amused at webamused.com
Fri Mar 17 13:45:56 EST 2000


Jeff Pinyan wrote:
> 
> [posted & mailed]
> 
> >while( notDone )
> >{
> >    int chip = this.getNumberOfSomething();
> >    if (chip == 10 )
> >    {
> >        System.out.println("Tjohoo");
> >    }
> >    else
> >    {
> >        System.out.println("Oh no!");
> >    }
> >}
> 
> I'll be a jerk, and do this brevity-style:
> 
>   while notDone:
>     print ("Oh no!","Tjohoo")[this.getNumberOfSomething() == 10]
> 
> Now, I ask you folk, is that "bad" Python?  Is that "bad" programming in
> general, to be brief and succinct like that?  I'm curious -- I have a
> tendency to do things like that. :)
> 

  I'd say that it is bad programming in general.  Tricksy succinctness
is the enemy of both readability and correctness, both of which are
vastly more important to any working program than saving you a few
keystrokes in coding it.  For instance, what happens when you have to
add code to account for the fact that notDone is never set in the loop
(unless as a hidden manipulation of a global in getNumberOfSomething)? 
Unless you make it even trickier, you're going to have to unpack that
print statement, and then how much time will you have saved writing it?


verbosity-in-defense-of-maintainability-is-no-vice-ly y'rs, Joshua



More information about the Python-list mailing list