I used to be a C++/Java man. So naturally when I first started with OOPerl it looked horrible to me. I thought it was just a badly written patch. I mean, what is all this
$self = shift; stuff? Why is there no proper 'this'? And where are all the private variables? So at first, I used perl for just functional programming.
But as I worked more with perl, I started missing the OO design for all its good at. Ever since I moved from Basic (GW/Quick/Visual) to C++ I was an OO thinker. So I finally decided I'll give OOPerl a chance.
Now, after doing some work, and even releasing my first CPAN module, I find that I like OOPerl better than Java/C++. That's because -
- It has all the stuff that makes perl such a fun language.
- You have a lot more room to play with your classes than you do in J/C++. for example - you can add properties to your objects on the fly (add to the hash then generate accessor subs at runtime), revert an object to its parent class (delete some hash keys then bless $self, $ISA[0]) and a lot of other stuff that are difficult in Java and nearly impossible in C++.
- You can use closures and subroutine references, thus creating for the user of your class a flexible, dynamic and extensible class when it is required (just like sort accepts a block of code to do the sorting).
I used all of this features, and felt a sense of freedom that you only get with perl.
However, there is one downside that I bothers me, and I'd like to read your opinion on it. I think there is an issue of security: You can't trust your class to be used the way you want it to. To demonstrate why this is important sometimes, think of Java's SecurityManager class: It controlls all activities in the JVM including file and inter-thread actions. If one could add and override functions in that class freely, that class would be useless. I don't know of any perlish way to totally encapsulate your classes to be unpenetrateable..
Is there such a way? Are there any other downsides (and upsides) that I am not aware of?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.