[Python-Dev] Adding C ternary select (a?b:c) to Python?
Jim Fulton
jim@digicool.com
Mon, 31 Jan 2000 10:04:45 -0500
Christopher Petrilli wrote:
>
> The question comes from what "problem" you're trying to solve.
It would allow you to incorporate logic into expressions.
There are contexts where only expressions are allowed, such as:
- lambdas
- DTML expr attributes
in which I'd very much like to incorporate tests.
> The ?: syntax
> does not introduce any new "functionality" to the language,
Yes it does.
> nor does it
> make it capable of solving problems or requirements that it can not do
> at the current time.
Ditto.
> The second qustion I'd ask is, who is this aimed at? It's certainly not
> aimed at first-time programmers, as I know from experience that the ?:
> is one of the hardest things to teach people in C (after pointers),
Hm. I can't agree.
Smalltalk, came out of an essentially CP4E effort
two decades ago at Xerox PARC. Smalltalk *only* had conditional
expressions. The message:
[condition] ifTrue: [do something ...]
ifFalse: [do something else ...]
is an expression in Smalltalk.
> and
> often I leave it out of training when I did it. It's simply a "shorthand"
> not a new functionality.
No, it allows testing in expressions.
> If its aimed at experienced programmers, I'd
> argue that it's at best "non-pythonic" and at worst a hack, taken from
> a language in which it exposes the "macro assembler" approach.
I don't agree.
> Python is not a language that has been optimized for "minimal typing",
That's not the issue.
> it's
> much more verbose than most languages, and so that argument shouldn' be
> applied. Perhaps it's for optimization? That was I believe the original
> argument made for it in K&R, in that optimizers in that day were rather
> antiquated, wheras today, I believe that any C compiler would get it
> right if it were expressed in its full form. (Timbot?)
>
> So, it comes down to a few questions for me:
>
> Does it solve a new problem? No
Yes.
> Is it pythonic? No
Pythonicity is relative.
> Does it make it faster? No
Who cares?
Jim
--
Jim Fulton mailto:jim@digicool.com Python Powered!
Technical Director (888) 344-4332 http://www.python.org
Digital Creations http://www.digicool.com http://www.zope.org
Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission. Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.