Don't ask to ask, just ask | |
PerlMonks |
RFC: Idiomless Perlby bennymack (Pilgrim) |
on Feb 02, 2007 at 02:33 UTC ( [id://597868]=perlmeditation: print w/replies, xml ) | Need Help?? |
Greetings, It's that time again. Time for another half-baked idea for a Perl extension. It's really not all that bad. In fact, I think it might be something that people may actually want to use. That being said, like many of my ideas it's not really an idea but application of another programming language's paradigms to Perl. In this case, Ruby. The reason I titled this "Idiomless Perl" is because it seems like it would be extremely useful to have a place to easily store snippets of code that are "idiomatic" and retrieved with as little extra effort as possible. Enter "OO::All". It would define some basic types as objects at first. With a base Object that is the super class for Scalar, Array, Hash (to start). Each child class would be represented by an object which is a blessed version of the primitive it is named after. E.g. bless( [], 'Array' ), etc. With a little overloading one could treat the object as both a primitive and an object if desired. A quick example of the usefullness of a such a module follows:
Which is effectively the same as:
Why you ask? Because keeping things like the correct context straight are "idiomatic". There are are so many other examples that show how useful this can be. Unfortunatetly this was the only one I could think of ATM. I understand there are modules on CPAN to add this sort of functionality. Ideally the actual implementation will come from CPAN and it will be trivial to roll it into the objects. Please don't take this as an OO fanboyism. It's really all about having somewhere convenient to store oft encountered snippets of idiomatic Perl. The more convenient it is, the more likely it is to be used, the less likely one might be to be burned by Perl idioms. I'm not scared of Perl idioms, don't get me wrong. I just think it would make code easier to write and get right as well as easier to read and understand. The implementation of this I have in mind would be something that can be loaded all from one central location and then be available everywhere. It would of course utilize a mixin where all the subs from a given module could be added into any of the object classes. Additionally, every method call (that I can foresee thus far) on these objects will return another object so they can easily be chained:
The keys method on Hash returns an Array whose count method returns a Scalar... Or there could just be a Hash method to return the key count but this is strictly illustrative. Thanks for reading! Let me know what you think. I will try to put some more examples down in writing as I think of them.
Back to
Meditations
|
|