Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^4: What if Perl had an OO standard library?

by awncorp (Acolyte)
on Aug 31, 2022 at 23:35 UTC ( [id://11146576]=note: print w/replies, xml ) Need Help??


in reply to Re^3: What if Perl had an OO standard library?
in thread What if Perl had an OO standard library?

Thanks for the feedback. I don't mean to be argumentative but if you write a Perl subroutine expecting a certain type of data (say a hashref), how do you handle the case where the routine is called with something else (say an integer).

As far as I can tell you only have two options: i.e. yolo! and let it crash, or try to do some simple sanity checking. The simple sanity checking is defensive programming (and you're forced to do it (or at the very least, coerced)).

The most recent release of Venus, v1.30, ships with a simple type assertion framework that all standard library classes utilize via the "make" method. The new method still allows value classes to accept bad values, intentionally. The idea is that "make" is useful in situations where you're unsure about the data being submitted. Obvisouly "make" (e.g. new w/type checking) is not as performant as "new".

Venus::Number->make; # Exception! Venus::Number->make(0,0); # bless(..., "Venus::Number") Venus::Number->make(1); # bless(..., "Venus::Number") Venus::Number->make('abc'); # Exception! Venus::Number->new([3,2,1]); # Exception! Venus::Number->new([3,2,1])->abs; # Exception!
"I am inevitable." - Thanos

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 12:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found