[OT] Perl woes and types

Ovid publiustemp-londonpm at yahoo.com
Wed Jan 28 16:47:56 GMT 2009

----- Original Message ----

> From: Peter Corlett <abuse at cabal.org.uk>

> > The problem with "strongly" and "weakly" typed is that different people define 
> them differently and they don't have much meaning in type systems.  It's static 
> typing and dynamic typing which is important.
> Wikipedia says that weakly- versus strongly-typed indicates how readily the 
> language coerces between types. I'm not sure one can get much weaker than Perl 
> on that front.

By "types" I assume you mean "kinds of data a variable can hold".  Strictly speaking, taint checking in Perl is another type system in the language, one which (like "use strict") must be explicitly enabled in the code.  There is a very specific action which is required to extract untainted data from tainted data, so Perl is "strongly typed" in this respect..  You also can't coerce an array reference into a hash reference though you can create them out of thin air via auto-vivification, but once created, you can't change 'em:

    $ perl -Mstrict -le 'my $foo = []; $foo->[0]{bar}[0] = "Wheee!"; print $foo->[0]{bar}[0]; $foo->[0]{bar}{baz}'
    Can't coerce array into hash at -e line 1.

So is Perl strongly or weakly typed? 

> > I *think* what you're describing as "strongly typed" is "a variable can hold 
> different types, but that operators change their behavior at runtime:
> That's just polymorphism, no?

Yes, but many argue that early binding is a key component of a strongly typed language.  The python example I posted clearly had different kinds (types) of data assigned to the 'foo' and 'bar' variables at different points in the program.

I'm just saying that while type theorists generally agree on the meaning of "static" and "dynamic" typing (and all languages contain elements of each), "strong" and "weak" typing don't have much meaning there.  They only have meaning to those who make up their own definitions :)

Buy the book         - http://www.oreilly.com/catalog/perlhks/
Tech blog            - http://use.perl.org/~Ovid/journal/
Twitter              - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6

More information about the london.pm mailing list