Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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 :-)


Comment on Re: Class::Struct, Class::Contract and type Safety
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2014-07-25 00:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (167 votes), past polls