[Python-ideas] Statements vs Expressions... why?
Cliff Wells
cliff at develix.com
Sat Sep 13 18:02:52 CEST 2008
On Fri, 2008-09-12 at 21:56 -0600, Adam Olsen wrote:
> At most, it's a *small* benefit to the language. It comes a tradeoff,
> just like a+b rather than add(a, b), or len(x) rather than x.len().
Okay, you kept providing this example and I kept brushing it off because
I didn't see where you were leading. Now I do and now I realize that
I've utterly failed to get the problem across.
Let's use your example from above: a+b vs add(a, b)
a + b is the *exact* semantical equivalent of add(a, b). They do the
same thing, they can be used in the same contexts. The + operator is
pure semantic sugar (and well-used sugar too).
Now let's imagine things aren't quite so equivalent. a+b has the same
result as add(a, b), except you can only use the + operator in one
particular context: assignment. It cannot be used say, with a comparison
operator.
So in my imaginary Python, this is legal
x = 1 + 2
but this is not
if x < y + 1: pass
and must instead be written
if x < add(y, 1): pass
Now lets make it even more of an exact comparison.
Let's say the add(x,y) function didn't even exist. You have to write it
yourself. Worse, writing it requires fairly deep knowledge of Python,
and worse yet, you sometimes must write a different add(x,y) function
depending on what context you want to use it in.
At this point we've now made your example much closer in spirit to the
problem I'm attempting to present.
> You're claiming we don't have to make that tradeoff.. but you've done
> *nothing* to substantiate that. Even logix only adds more complexity,
> rather than removing and unifying existing syntax.
And you've provided nothing to substantiate this (aside from this
assertion).
Also, if we combine statements into expressions, how does this not unify
existing syntax? Combining two into one is practically the definition
of "unify".
> We don't care about purity. Statements vs expressions.. functional vs
> imperative.. they're tools, pure and simple. We switch back and forth
> as appropriate. Most of the time quietly, subtly, such that you
> usually don't even notice we've done it. We like it that way.
Who is this "we"? People who use Python? Am I not a person who uses
Python (and for the better part of 10 years I might add). I'm not some
outsider saying "can you add X from my previously favorite language Y so
I can program the way I used to". I'm someone who, until maybe a year
ago, was just as narrow-minded about Python's shortcomings as you are
now. I mean seriously, has it occurred to you that it's possible that
you simply aren't getting my point?
> You'll be a lot more productive if you learn to relax, concerning
> yourself with use-cases, not ideals.
Thanks for the advice. Should I also read a good book, maybe consider a
massage?
Regards,
Cliff
More information about the Python-ideas
mailing list