Perl is worse!
Ben Wolfson
rumjuggler at cryptarchy.org
Fri Jul 28 05:21:28 EDT 2000
On Fri, 28 Jul 2000 08:11:18 GMT, grey at despair.rpglink.com (Steve Lamb)
wrote:
>On Fri, 28 Jul 2000 01:24:08 -0400, Tim Peters <tim_one at email.msn.com> wrote:
>>Steve, in case it isn't clear yet, Python programmers *want* to be blown out
>>of the water when doing something as senseless as
>
>> 1 + "foo"
>
> It isn't senseless. That is the whole point. It is only senseless
>because of typing. Clearly you cannot add a word to a number, granted. But
>what of 1 + "1"? That isn't senseless, those are two numbers. I can see they
>are two numbers, it is only because of typing that it fails.
>
> So I ask you this /VERY/ simple question. Why can't Python do both? Hm?
>What is wrong with taking 1 + "1", converting the "1" to a 1 and adding it
>together? If it is a string that cannot be converted to an integer, throw an
>exception, otherwise, do it. Then that preserves the 1 + "foo" exception and
>also does the sane thing of getting rid of types when it makes sense to do so.
Well, what if you wanted
1 + "1"
to result in "11", not 2?
> Hell, why do an exception at all? Why not do what is already done with
>integers, reals and floats?
>
>1 + 1 = math
>
>1 + "1" = math
>
>1 + "foo" = string ("1foo")
That could lead to some interesting results if you expect numerical input.
>"foo" + "foo" = string ("foofoo")
>
> You already accept:
>
>1 + 1 = integer
>
>1 + 1.2 = float
>
>1 + 1j = complex
>
> So please don't tell me you don't want "automagic" type changing when it
>is already there and, I'd wager, you use it extensively.
Those are all numeric types. I don't see why you don't also start arguing
for the validity of
list(1 + ['4', someclassinstance] + "lalala")
--
Barnabas T. Rumjuggler
93. When someone says "I want a programming language in which I need only
say what I wish done," give him a lollipop.
-- Alan Perlis <http://www.cs.yale.edu/homes/perlis-alan/quotes.html>
More information about the Python-list
mailing list