perlmeditation
yosefm
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 <code>$self = shift;</code> stuff? Why is there no proper 'this'? And where are all the private variables? So at first, I used perl for just functional programming.
<p>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.
<p>Now, after doing some work, and even releasing my first [cpan://Javascript::Menu|CPAN module], I find that I like OOPerl better than Java/C++. That's because -
<readmore>
<ul>
<li>It has all the stuff that makes perl such a fun language.</li>
<li>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 <code>bless $self, $ISA[0]</code>) and a lot of other stuff that are difficult in Java and nearly impossible in C++.</li>
<li>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).</li>
</ul>
I used all of this features, and felt a sense of freedom that you only get with perl.
</readmore>
<p>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 <b>security: </b>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..
<P> Is there such a way? Are there any other downsides (and upsides) that I am not aware of?