Tuesday, February 09, 2021

Differently Right

Philosophical Aside 

In its OO [Object-Oriented] programming, Perl gives you a lot of freedom: the ability to do things more than one way (you can bless any data type to make an object), to inspect and modify classes you didn't write (adding functions to their packages), and to use these to write tangled pits of misery -- if that's really what you want to do.  

Less flexible programming languages are usually more restrictive.  Many are fanatically devoted to enforced privacy, compile-time type checking, complex function signatures, and a smorgasbord of other features.  Perl doesn't provide these things with objects because it doesn't provide them anywhere else, either.  Keep this in mind if you find Perl's object-oriented implementation weird.  You only think it's weird because you're used to another language's philosophy.  Perl's treatment of OO is perfectly sensible -- if you think in Perl.  For every problem that you can't solve by writing Perl as though it were Java or C++, there is a native Perl solution that works perfectly.  

Perl's objects are not wrong; they're differently right.

-- Tom Christiansen and Nathan Torkington in "Perl Cookbook", Chapter 13. "Classes, Objects, and Ties", O'Reilly (1998)

No comments: