in reply to Re: What if Perl had an OO standard library?
in thread What if Perl had an OO standard library?
No offense intended.
The remark that "sustained object-orientation in Perl is difficult …" is just my own fancy way of saying that “treating everything as an object is difficult/manual in Perl”. Data will always enter your program in its raw primitive form, and while you can objectify it (bless it), 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. Consider the following examples (you made a routine and you want to compare anything passed in) ...
Note: smatchmatch is experimental and not recommended for production use
sub compare_things { $_[0] ~~ $_[1] }
example #1
compare_things(1, '') ''
example #2
compare_things('', '') 1
example #3
compare_things(1, []) ''
example #4
compare_things(1, bless{}) Died! Smart matching a non-overloaded object breaks encapsulation
example #5
compare_things(0, '') ''
example #6
Venus::Number->new(0)->eq('') # DMMT and DWIM 1
example #7
Venus::Number->new(0)->tv('') # (tv) type and value equality 0
example #8
Venus::Number->new(0)->eq(bless{}) # DMMT and DWIM 0
|
|---|