$10K coding deathmatch

Andrew McNabb amcnabb at mcnabbs.org
Mon Nov 6 14:56:52 MST 2006


On Mon, Nov 06, 2006 at 02:18:04PM -0700, Levi Pearson wrote:
> 
> I agree, they should not be used as such if there's an alternative.   
> Pre-1.5 python apparently doesn't supply a conditional expression,  
> though.

The only reason you need a conditional expression is if you're thinking
in Lisp.  I've done a tiny bit of Scheme, and I actually think it's
really cool, but Python isn't Scheme.

You can't honestly believe that you should use boolean expressions in
this case, just to show how mad you are that Python doesn't have
conditional expressions.  I don't care how angry and frustrated you are
at Guido as you begrudgingly use conditional statements, but that's no
excuse for going postal and using boolean expressions.

> >Also, you shouldn't inline a function unless it's short and concise.
> >It's really not hard to put a def statement just before the reduce.
> >
> 
> That looked like a pretty short function to me.

It's too long to be appropriately inlined in Python.  In other languages
like Scheme, it probably would have been just fine there.

> Yes, but there is a difference between conditional statements and
> conditional expressions.  One fits in the 'statements' parts of the
> grammar while the other fits in the 'expressions' parts of the
> grammar.

I agree completely. :)

Python's design explicitely encourages conditional statements rather
than conditional expressions.  Some of us like this design decision;
others dislike it.  I'm fine with people wanting conditional
expressions, but Python isn't the right place.  You really have three
choices:

1) Write "Pythonic" code with conditional statements.

2) Decide that conditional expressions are so important to you that you
would rather use another language (this is a perfectly rational
decision)

3) Write code that's so ugly that you're sure that Python users will be
convinced that they really want conditional expressions, just to get you
to stop writing such ugly code.

> 
> [...] relying on a type error for an early exit.  I'm surprised you
> didn't mention that one yourself, since I find it by far the worst
> offense.  And none of it really warrants shooting, unless the Python
> Police are truly as draconian as you suggest. :)
> 

I agree that the TypeError for exit is evil, I just got off on a roll on
the conditionals. :)

I can't speak for the Python Police, but sometimes I think we need some
stricter laws to keep everyone in line, as long as I'm the one deciding
what the rules are.  Maybe that's why none of my friends would ever vote
for me for world dictator. :)

-- 
Andrew McNabb
http://www.mcnabbs.org/andrew/
PGP Fingerprint: 8A17 B57C 6879 1863 DE55  8012 AB4D 6098 8826 6868



More information about the PLUG mailing list