[Python-ideas] [Wild Idea] Static Ducks

Steven D'Aprano steve at pearwood.info
Tue Sep 22 01:18:54 CEST 2009


On Mon, 21 Sep 2009 11:55:57 pm MRAB wrote:
> I know of one language which is weakly typed: BCPL. It's only type is
> the bit pattern. It's the function or operator which interprets the
> bits as representing a certain value.

That would make BCPL an untyped language, like assembly. If the language 
has no types, it can't be either weakly or strongly typed.

Weak and string typing is a matter of degree. Most languages are weakly 
typed to some extent, for instance Python will automatically coerce 
various number types so you can add integers to floats etc., as will 
Pascal. Numeric coercion is so widespread that most people consider it 
an exception to weak typing: if all the language coerces are numeric 
types, then it's still strongly typed.

The classic test for weak typing versus strong typing is operations on 
mixed integers and strings. Can you add or concatenate strings to 
integers without an explicit conversion? Perl is weakly typed:

$ perl -e 'print "2"+2; print "\n";'
4
$ perl -e 'print "2".2; print "\n";'
22

PHP and (I think) Javascript will do the same.

It's been some years since I've used it, but I recall Apple's Hypertalk 
behaved similarly. I think you could say 2&"2" (returns "22") and 2+"2" 
(returns 4). Hypertalk is no longer supported, but I expect Apple's 
current generation scripting language, AppleScript, would probably be 
the same.



-- 
Steven D'Aprano



More information about the Python-ideas mailing list