Formal mix-ins

Description

From: https://issues.jboss.org/browse/RAILO-3215

See http://blog.adamcameron.me/2014/09/looking-at-phps-oop-from-cfmlers_10.html

Both PHP and Ruby (and no doubt various other languages) have a formal concept of mix-ins.

PHP does it with traits http://php.net/manual/en/language.oop5.traits.php; Ruby does it with modules: http://ruby-doc.com/docs/ProgrammingRuby/html/tut_modules.html.

Having messed around with both, I find it a good technique for composing a class, and would alleviate a lot of the artificial dependency injection CFMLers need to do to effect similar results.

This has kinda been raised before - RAILO-65 - but this was closed, due to - I think - Micha not quite "getting it", as his explanation missed the point.

I think it should be reconsidered, but after Micha's done more research and experiementation as to how other languages leverage this sort of thing.

Activity

Show:

Sean Corfield 7 December 2015 at 18:05

Adam Cameron 16 November 2015 at 09:33
Edited

My position has drifted somewhat since I raised this.

  1. The CFML implementation should not do anything ColdFusion doesn't do. So this should not be considered in that context.

  2. One of the challenges this would have mitigated in CFML is that included functions don't contribute to interface compliance (should that be what the mix-in is being used for). However for .lucee you probably shouldn't bother implementing interfaces anyhow, so it's moot.

  3. One handy thing with mix-ins is that one can have standardised function names in the mix-in, and then rename them during the mixing-in process to match the requirements of the class they're being mixed-in to. Also method access can be controlled too. This is the one area they trump dumb includes. However I dunno how much benefit this is.

  4. I have close to zero interest in .lucee (the mooted "language", not the general LAS project), so it seems "inappropriate" for me to be suggesting feature requests for it.

So can I downvote my own ticket?

Dominic Watson 16 November 2015 at 09:22

I created a language forum topic in which to discuss the topic here: http://lang.lucee.org/t/implementing-native-mixin-functionality-for-components/262

We should carry on the conversation there (happy to modify the topic description too, please DM me if you feel its off).

Sean Corfield 15 November 2015 at 02:35

Based on Kai's input, moving to Public Consultation (with the expectation, at least from me, that we'll find the existing functionality to be satisfactory and will reject this ticket

Since Lucee allows multiple definitions of a function with last-definition-wins, you have control over whether "local" definitions (in the CFC) override the mixin or not, based on the position of the include (although someone should verify that). I'd be fairly certain – pending Adam's investigations – that including a CFC would override inherited methods, since the include is going to bring in method definitions at runtime.

Kai Koenig 15 November 2015 at 00:53

I think we'd agree that from a functionality point of view, a simple include in CFML can do very similar things to what Traits and Modules in their respective languages do.

Traits seem to have a quite a bit of rules and definitions around what happens when it comes to overriding methods for instance - I'm not sure what would happen in various of the scenarios listed here http://php.net/manual/en/language.oop5.traits.php when trying to rebuild them with CFML includes.

I'm not fundamentally opposed to investigating such a concept, however, I'd like someone (maybe ) to investigate a bit further what's currently possible with CFML, how the current "implementation" with includes would work for those example cases with Traits in PHP and if there's anything that can't be easily done at the moment.

Details

Assignee

Reporter

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Priority

Created 1 February 2015 at 15:54
Updated 7 December 2015 at 18:05