[Python-ideas] [Wild Idea] Static Ducks

Masklinn masklinn at masklinn.net
Tue Sep 22 22:55:09 CEST 2009


On 22 Sep 2009, at 22:17 , Steven D'Aprano wrote:
> On Wed, 23 Sep 2009 02:35:49 am Masklinn wrote:
>> 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.
>
> What are you talking about? Using Python syntax, we might write:
>
> assert "2"+2 == 4
>
> This test will FAIL for Python, Pascal and other strongly typed
> languages, and PASS for weakly typed languages. (For some languages,
> like Pascal, you can't even compile the test!)
>
Ah I see, we used different meanings for "fail" here. I was thinking  
of "failing the test" by accepting to run this piece of code (which I  
find obviously incorrect).

>
>>> If you're only criterion is that an operation is well-defined,
>>> then "weak typing" becomes meaningless...
>>
>> I don't think I defined any criterion of strong/weak typing.
>
> You conceded that C# adds strings and ints, but disputed that this  
> fact
> makes C# weakly typed on the basis that (I quote) "the operation is
> well defined".
I didn't dispute C#'s strong or weak typing (again, I consider this  
line of inquiry utterly worthless). I merely noted that the operation  
was clearly defined in the documentation, and am sorry if it came out  
as anything but a "note of interest".

> There's nothing about the definition of weakly typed
> languages
There is not definition of 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.
>
> I agree that treating weak/strong as a binary state is an
> over-simplification, but a weak/strong axis is perfectly reasonable.
I really don't think so. Once again, because there is nothing formal  
about the concept, and everybody just make up their own definition of  
the axis as they go.


More information about the Python-ideas mailing list