[Python-ideas] [Wild Idea] Static Ducks
masklinn at masklinn.net
Tue Sep 22 16:25:32 CEST 2009
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.
> According to Wikipedia, C# is strongly typed. The only implicit
> conversions are "safe" conversions, such as widening integer types
> (e.g. convert 32-bit ints into 64-bit ints, but not the other way),
> some implicit conversions between derived types and their base types.
> The rules are relaxed a little for the int literal 0. I assume that,
> like most languages, it allows mixed int/float arithmetic.
See above: C#, much like Java, also allows concatenating anything to
strings, and implicitly convert non-strings to strings.
More information about the Python-ideas