Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by awncorp (Acolyte)
on Aug 24, 2022 at 00:18 UTC ( [id://11146349]=note: print w/replies, xml ) Need Help??


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

"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://11146349]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-26 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found