Reply to David Golden "Comparison of Class::Tiny and Object::Simple"

p5p pumpking David Golden wrote the following topic.

Comparison of Class::Tiny and Object::Simple

I'm pleasure he is interested in Object::Simple even if the entry criticize Object::Simple.


----------------------------------------
Yes, you can create custom constructors, but that defeats the syntactic simplicity of Object::Simple.
----------------------------------------

No, No. Custom constructor is very very easy. Nothing is difficult.


-------------------------------------------
Very soon, you'll have re-invented the semantics of BUILD/DEMOLISH.
-------------------------------------------

No, No. Perl calls constructors and destructors in correct order if we use only single inheritance.

I strongly recommend single inheritance in object-oriented programming.

See Object::Simple(CPAN) for more details. I add FAQ section to reply this question.

6 Comments

David Golden is not the p5p pumpking.

Sorry, I have mistake? In Past?

Not in the past either. David Golden is not the pumpking now and has never been the pumpking before.

Perl calls constructors and destructors in correct order if we use only single inheritance.

This is… not even wrong.

Perl calls one single destructor – the first one it finds in the inheritance hierarchy. A single constructor is called also, since they are just methods in Perl, and a method call only calls one method. Talking about a “correct order” for one single thing is nonsense. I can only assume you did not understand what David was talking about at all.

The point is:

Perl doesn’t provide any help for overriding constructors or destructors. The user has to do everything manually.

Moose, Moo and Class::Tiny provide an interface to abstract this away (BUILD/DEMOLISH).

Object::Simple doesn’t.

I'm flattered to be called Pumpking, but I've only been a release manager, never Pumpking. (I'm not temperamentally suited for that role anyway.)

As Aristotle points out, BUILD/DEMOLISH are a convention to let a provided constructor and destructor call customizations in the right order in a class hierarchy (for single or multiple inheritance).

The alternative is for every class to provide new/DESTROY that also call the superclass new/DESTROY (and in the right order). That's a little bit more work than just writing BUILD/DEMOLISH, particularly as DESTROY is a bit tricky around exception handling.

I'd love to see Object::Simple add BUILD/DEMOLISH support (along with the '__no_BUILD__' convention for interoperation with Moo/Moose). Then it would be a very reasonable alternative for people looking for a simple and correct OO framework.

> See Object::Simple(CPAN) for more details. I add FAQ section to reply this question.
It will be usefull to see link to this article in module doc too:
http://www.dagolden.com/index.php/2675/comparison-of-classtiny-and-objectsimple/

@xdg: and in the Class::Tiny too

For example in the SEE ALSO section.

Leave a comment

About Yuki Kimoto

user-pic I am Yuki Kimoto, Japanese Perl programmer. I create tutorial site in Japanese, and I create Perl modules and Perl Applications.