in reply to Time efficiency of object creation in Perl (or the "bless" function)
As salva shows the bless is probably not where the time is. The cost is probably in the method calls. However the a benefit of an object is in added value in methods rather than just wrapping a hash up in a layer of setters and getters. Perl lets you mix and match styles to a very large extent so there need be no particular disincentive to exposing some of the tender underbelly of your objects by allowing direct access to the object's data as a pragmatic solution to a problem.
You can use speedy access to a hash and added value methods to get both the benefits of a hash and the benefits of an object. In fact, after a modest debate with a colleague recently I did exactly that for a class passed out of an API function. The 'public' fields of the object are well documented and are freely accessible by calling code. It helps that there is no interaction between fields and any 'sensitive' data is tucked away in undocumented (therefore notionally 'private') fields. The objects are used to provide access to a database back end and the methods on the object are mostly private functions concerned with translating the data between the public form for calling code and the form required by the database. Thus cheap and easy access to data fields and nice encapsulation of the database facing code.
|
|---|