[OT] Perl woes
nick at ccl4.org
Wed Jan 28 14:46:30 GMT 2009
On Wed, Jan 28, 2009 at 02:21:45PM +0000, James Laver wrote:
> On Wed, Jan 28, 2009 at 2:02 PM, Peter Corlett <abuse at cabal.org.uk> wrote:
> > Python is dynamic and manages this just fine:
> > $ python
> > Python 2.5.2 (r252:60911, Aug 6 2008, 09:17:29)
> > [GCC 4.3.1] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> >>>> '1' + '2'
> > '12'
> >>>> 1 + 2
> > 3
> >>>> 1 + '2'
> > Traceback (most recent call last):
> > File "<stdin>", line 1, in <module>
> > TypeError: unsupported operand type(s) for +: 'int' and 'str'
> That's because python is strongly typed (though not statically typed
> -- it's a dynamic language).
> I suppose perl is strongly typed as for the difference between
> scalars, lists etc., it just doesn't care what's in a scalar (without
> discussion of the internals at any rate).
> So if we update Nick's statement to reflect that perl's typing system
> is weaker, then his point stands perfectly.
Fair enough. But it's also that with this Perl:
$c = $a + $b;
$d = $a . $b;
then at compile time (heck at writing it time) I know what it is going to do*
It doesn't depend on the types, at run time, of the values within the
variables. Whereas in Python, what the same '+' operator in the same line
does is determined only at run time:
Python 2.4.3 (#1, Sep 17 2008, 16:07:08)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-41)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def munge(a, b):
... return a + b
>>> munge(1, 2);
>>> munge('a', 'b');
>>> munge(1.2, 3.4);
Hence, I'm stating that you can't tell the intent of the '+' operator from
the code alone:
def munge(a, b):
return a + b
* modulo people being "clever" with overloading, but the same is true in any
language that allows operator overloading.
More information about the london.pm