[Python-ideas] [Wild Idea] Static Ducks

Steven D'Aprano steve at pearwood.info
Tue Sep 22 15:16:16 CEST 2009

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. I can imagine a 
language which requires explicit conversions between ints and strings, 
while implicitly converting or casting nearly every other data type!

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), and 
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.

This is quite similar to Python, which also implicitly widens ints to 
long ints. Arguably Python is weaker than C#, as Python accepts any 
object in truth concepts, while C# requires an actual bool type.

I'd be surprised if C# implicitly converts strings to ints, but if it 
did, that would be a good example showing that the strength of the type 
system is not a one dimensional quantity.

Steven D'Aprano

More information about the Python-ideas mailing list