2009-09-29

multiple inheritance - why still using it

ovid reacted to the bug i opened against exporter and multiple inheritance, stating that we cpan authors shouldn't use multiple inheritance, since roles exist.

with all due respect to ovid, this is over-simplifying. cpan holds 15000+ distributions, of which maybe 5% is proposing a role-based api (and i think i'm generous). which means that a lot of the modules available needs you to inherit from them[0]. so what to do when you want to use those modules? yup, multiple inheritance. i know it's bad - but i don't have the choice, mmk?[1]

i can already predict ovid's answer: my bug was related to inheriting from both exporter and class::accessor::fast[2], so i should switch to moose to replace the class::accessor bit. right, i plan to do it later on (patches welcome, too).

but in the meantime, i have a module that worked perfectly under 5.10.0, and that breaks under 5.10.1 (i am still not sure if it's perl or exporter or base/parent related). no need to talk of greypan and compatibility accross major perl releases: i'm talking of backward compatibility of minor perl version for regular cpan module with code available here. and even if it's using sub-standard technology - i am entitled to not expect this kind of breakage.


[0] which is not exactly surprizing, since roles are quite new in perl's oo landscape: 2.5 years according to moose's changelog. if you count some time to let the new feature stabilize, get some needed speed boost and gain acceptance, i don't expect to see a lot of non-role based api soon.

[1] i'm not advocating to use multiple inheritance at all costs. ovid is right: if you can, compose classes with roles. really, he is right on this topic. however, the key words here are if you can.

[2] see how both synopsis request you to inherit from them?

2 comments:

  1. Are you certain this is due to a change in perl from 5.10 to 5.10.1? It looks like it is due to changes in Class::Accessor from 0.33 to 0.34. In 0.33 and previous versions it didn't have an import method, so it didn't interfere with Exporter.

    ReplyDelete
  2. @haarg: yup, check my other post (http://jquelin.blogspot.com/2009/09/about-exporter-bug.html) where i explain the problem. as you said, it's related to class::accessor.

    ReplyDelete