[Chicago] newbie says HI; needs help
Ted Pollari
tcp at uchicago.edu
Fri Jan 20 17:18:46 CET 2006
On Jan 20, 2006, at 8:26 AM, Andrew Dudzik wrote:
> The problem with learning Python from a Pascal book is that you're
> going to miss all of the syntactical shortcuts that makes Python
> powerful. For instance, you could use the line 'if texture in
> ["flaky","caked"]'.
I'd agree with that and go a bit further by saying that it's all of
the syntactical structure (and shortcuts) that makes Python powerful
and yet eminently readable. The "if texture in ['flaky','caked']"
expression is very readable and if there were more options in the
list, it would be an even better simplification than having to write
out the cases in a logical or'd conditional statement. It's the
readability that makes Python easy to learn and understand as well as
easy to come back to after you've left it for a while.
> There's definitely a good one-liner for this, (the veterans should
> chime in here) but the best I could come up with was this one:
> (it's a hack)
>
> stock = 2 - (texture in ["flaky","caked"])
Sure, that works, but yeah, it's it's a hack =), just as you said.
If you need to optimize some block of code, have your way with it and
make it as difficult to read/understand as you need but otherwise I
say focus on making it work and work clearly/cleanly. (Especially if
you're going to come back to the code a ways down the road or if
someone else has to read your code) -- remember, there's usually a
tradeoff between compactness of code and readability/
comprehensibility (of course, this trend quickly reverses itself as
code bloats, but I digress...)
--
Ted Pollari
Research Programmer
Department of Health Studies
The University of Chicago
tcp at uchicago.edu
773.834.0559
More information about the Chicago
mailing list