Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Class::Struct, Class::Contract and type Safety

by baku (Scribe)
on Feb 14, 2001 at 19:51 UTC ( #58362=note: print w/replies, xml ) Need Help??

in reply to Class::Struct, Class::Contract and type Safety

Perhaps (probably) I don't rightly understand the question... but in my experience, the very fact that Perl is "weakly" typed has been a boon in large projects. For example, one current job I'm working on has over 500 separate small scripts (automated jobs working with various databases to perform specific functions) as well as several multi-thousand-line application "scripts," being maintained by as many as 50 people at any time. Since we don't have to worry about whether a subroutine expects a int or a long int, development has been remarkably easy.

That said, every named subroutine we have does perform checking, not upon the "type" of the data, but upon its "domain." For example:

sub member_bleh { my $self = shift; $self->validate(); # will die() if data is invalid if (@_) { my $value = shift; if ($value < 15 or $value > 143.51) { die ("$value out of range (15 .. 143.51) in member_bleh"); } $self->{member_bleh} = $value; } return $self->{member_bleh}; }

It looks like Class::Contract could be a useful tool to perform this sort of data validation, but relying upon "types" as a validity test (at least primitive types) is a very dangerous thing. OTOH, Perl does allow you to check object references, so if you accept data in the form of an object which contains already-validated data, you do have a "strong typing" system to work with: die "not Right::Class: $ref" unless ( ref $ref && $ref->isa("Right::Class") ); is one such example...

Hope that is on task :-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://58362]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2019-07-21 18:54 GMT
Find Nodes?
    Voting Booth?
    If you were the first to set foot on the Moon, what would be your epigram?

    Results (9 votes). Check out past polls.