A Tiny Affordance

What's wrong with this picture?

use parent qw/DBIx::Class::Core/;

Whenever I see that, I've started slowly but surely converting that to this:

use parent 'DBIx::Class::Core';

The problem with using the qw/STRING/ syntax is that it practically encourages multiple inheritance. Is says "gimme a list, really", except that you don't want a list, really. Even a subtle encouragement towards multiple inheritance is a Bad Thing.

9 Comments

I concur with my learned friend.

But you know there's a PPI API for that...

Read through PPI::Transform, craft a small transform class, and then you can use the transform API to apply it to anything you want.

See perldoc -f use (http://perldoc.perl.org/functions/use.html). The thing that follows the module (pragmatic) name is a list. When you place a single item (scalar) there, it is automatically converted to a list.

I don't know if multiple inheritance is a good thing but all the modern object-oriented languages have it, so I'll reserve judgment.

I think multiple inheritance is a bad thing, but it's good that it's available to us. Once we can more easily alter method dispatch, it will almost be an appendix, though.

Having "enough rope" is almost always a good thing. Keeping most of it under lock and key in the shed is also a good thing.

I've been doing the same thing as Ovid, for the same reason, for a while now, and I'm glad to hear that I am not singularly weird in doing so.

I use the single-quote style because it's shorter and clearer. Why spend the extra two characters making a single-element list when you can make a single-element list without an additional syntactic construct?

I hadn't considered that the quoting construct was an affordance toward multiple inheritance, but I had realized it was an affordance toward passing more options to import().

So, why is multiple inheritance a bad thing? It's a matter of taste IMHO

Well... The main problem seems to be "the diamond" AFAICT, but I'm not sure if this applies to Perl itself since the classes and inheritance is always ordered and you don't need to guess which method is invoked unless some weird things are done inside the methods. But I must admit I wasn't bitten by this problem I sure don't know if it's really bad :)

Leave a comment

About Ovid

user-pic Freelance Perl/Testing/Agile consultant and trainer. See http://www.allaroundtheworld.fr/ for our services. If you have a problem with Perl, we will solve it for you. And don't forget to buy my book! http://www.amazon.com/Beginning-Perl-Curtis-Poe/dp/1118013840/