[Python-ideas] [Wild Idea] Static Ducks

Michael Foord fuzzyman at gmail.com
Tue Sep 22 22:37:01 CEST 2009

2009/9/22 Masklinn <masklinn at masklinn.net>

> On 22 Sep 2009, at 17:46 , Steven D'Aprano wrote:
>> On Wed, 23 Sep 2009 12:25:32 am Masklinn wrote:
>>> On 22 Sep 2009, at 15:16 , Steven D'Aprano wrote:
>>>> On Tue, 22 Sep 2009 01:05:41 pm Mathias Panzenböck wrote:
>>>>> I don't think this is a valid test to determine how a language is
>>>>> typed. Ok, C++ is more or less weakly typed (for other reasons),
>>>>> but I think you could write something similar in C#, too. And C#
>>>>> is strongly typed.
>>>> Weak and strong typing are a matter of degree -- there's no
>>>> definitive test for "weak" vs "strong" typing, only degrees of
>>>> weakness. The classic test is whether you can add strings and ints
>>>> together, but of course that's only one possible test out of many.
>>> And it's a pretty bad one to boot: both Java and C# allow adding
>>> strings and ints (whether it's `3 + "5"` or `"5" + 3`) (in fact they
>>> allow adding *anything* to a string), but the operation is well
>>> defined: convert any non-string involved to a string (via #toString
>>> ()/.ToString()) and concatenate.
>> I don't see why you say it's a bad test. To me, it's a good test, and
>> Java and C# pass it.
>>  Uh no, by your criterion they fail it: both java and C# do add strings
> and integers without peeping.

C# will not allow you to add strings to numbers, this is nonsense. If you
call ToString() then this is an explicit operation to produce a string
representation - and it is this string that you add. It is *not* at all the
same as adding arbitrary objects on strings. You can't compile a C# program
that attempts to add strings and numbers.

I'm also pretty sure you can't override the default behavior on integers etc
(C# does have operator overloading but doesn't allow you to redefine
operators on the fundamental types - Java doesn't even have operator


>  If you're only criterion is that an operation is well-defined,
>> then "weak typing" becomes meaningless: I could define addition of
>> dicts and strings to be the sum of the length of the dict with the
>> number of hyphens in the string, and declare that
>> {'foo':'a', 'bar':'b'} + "12-34-56-78-90"
>> returns 6, and by your criterion my language would be strongly typed. I
>> think that makes a mockery of the whole concept.
> I don't think I defined any criterion of strong/weak typing. As far as I'm
> concerned, and as I've already mentioned in this thread, the whole
> weak/strong axis is meaningless and laughable.
>  This heuristic is not arbitrary.
> Of course it is.
>  Automatically converting ints to floats
>> is mathematically reasonable, because we consider e.g. 3 and 3.0 to be
>> the same number.
> Do we? Given 3/2 and 3.0/2 don't necessarily give the same answer (some
> languages don't even consider the first operation valid), I'm not sure we
> do.
>  Perl is weakly typed but it's very hard to cause it to crash,
> See the link I previously gave, you might consider Perl weakly typed, not
> everybody does.
>  while C++ is strongly typed but easy to cause it to core-dump.
> See my response to your previous declaration.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090922/489719a3/attachment.html>

More information about the Python-ideas mailing list