[Python-ideas] [Wild Idea] Static Ducks

Masklinn masklinn at masklinn.net
Tue Sep 22 18:35:49 CEST 2009

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.

> 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.

More information about the Python-ideas mailing list