Is there any trick to gain some of the benefits of static typing in perl?
e.g.

- ensuring that a variable of one type can only be assigned to a variable
of the same type (or to an instance of a parent class) -- not really caring
about string scalars vs. number scalars, but concerned about scalars vs.
objects, and objects of different types

- defining the return type of a function, so that its return value can only
be assigned to variables of the same type

Some of these kinds of mistakes might be caught at run time anyway (e.g. if
you treat one object like a different kind of object, then you'll get an
error trying to call a method that it doesn't support).  But since that
checking happens at run time, you could have mistakes hidden away in
sections of code that rarely get executed.  e.g. the following code runs
fine even with "-w" and "use strict":

>>>
use strict;
my $x = 3;
if (0)
{
        $x->func;  # $x is a scalar!
}
>>>

In a real program, the line above might be in a section of code that rarely
gets called, so that the bug isn't discovered until it's already caused
lots of trouble.

This is exactly the kind of programming error I'm looking to avoid -- any
suggestions?  (Other than "stay awake" :) )

        -Bennett

[EMAIL PROTECTED]     http://www.peacefire.org
(425) 649 9024
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to