the lack of a native type system means that your classes and methods can’t be certain of the type of data they’re being passed, which forces you into a position of defensive programming
Well, in my view Perl does never force me into any position, but, depending on the task, defensive programming is recommended.
Using objects as a surrogate for a type system is just a thin layer. For safety, this only helps if the classes do the appropriate validations on object creation. For example, Venus::Number accepts any value, so my classes and methods still can't be certain of the type of data they're being passed:
use 5.028; use warnings; use Venus::Number; use File::Temp; my $n; # These two come with warnings say Venus::Number->new($n); # '' say Venus::Number->new($n,$n); # 0 $n = 1; say Venus::Number->new($n); # 1 $n = "abc"; say Venus::Number->new($n); # abc $n = [3,2,1]; say Venus::Number->new($n); # ARRAY(0x...) say Venus::Number->new($n)->abs; # 94653281131368 $n = File::Temp->new; say Venus::Number->new($n); # /tmp/ER2Mi14BOz
In reply to Re^3: What if Perl had an OO standard library?
by haj
in thread What if Perl had an OO standard library?
by awncorp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |