digitalmars.D - mixins
- Walter (5/5) May 16 2004 I have this mostly implemented. It's been based on a lot of your
- J Anderson (4/10) May 16 2004 Wow, this is really nice.
- k.inaba (9/10) May 16 2004 Coooool!!
-
Walter
(3/12)
May 16 2004
Yes
. - Hauke Duden (23/29) May 16 2004 Looks good so far. But two things:
- Walter (5/25) May 16 2004 Fixed.
- Hauke Duden (4/12) May 16 2004 Oh yeah, forgot to mention: THANKS very much for implementing this! I
- Walter (7/18) May 16 2004 That
- Andy Friesen (41/46) May 16 2004 Singletons come to mind:
- Walter (3/49) May 16 2004 Would it make sense to put the private this() inside Singleton(T) ?
- Andy Friesen (4/6) May 16 2004 You could, but it's almost completely fire-and-forget as written.
- Mike Swieton (8/14) May 16 2004 How about putting a class invariant in the mixin that assert(instance is
- Andy Friesen (5/17) May 16 2004 You can only have one invariant per class, though.
- C. Sauls (7/8) May 16 2004 I'm planning on using mixins in Sinbad for exactly that purpose. (See
- Regan Heath (7/51) May 16 2004 Aren't you missing a line, see below. :)
- Andy Friesen (3/5) May 16 2004 doh. Yes. The approach is sound, though.
- Regan Heath (5/9) May 16 2004 Yes, I only mentioned the mistake cos I reckon everyone has copied it an...
- Hauke Duden (14/42) May 16 2004 Well, right now I see mixins as a way to upgrade the language to the
- fred (32/53) May 16 2004 charset="Windows-1252"
- Walter (3/3) May 16 2004 charset="Windows-1252"
- Pablo Aguilar (8/26) May 17 2004 I do a lot of GUI programming (in C++ mostly, a little C#) and the first...
- Matthew (4/24) May 17 2004 I've got one of those - and the article half planned - as soon as I have...
- imr1984 (3/8) May 16 2004 so i guess this means that structs can have inheritance now (in a way)? ...
- Ben Hinkle (49/55) May 16 2004 Cool! Will something like this work:
- Russ Lewis (7/13) May 16 2004 I was really excited to read the proposal. As usual, you take our ideas...
- Walter (7/20) May 16 2004 That
- Patrick Down (19/26) May 16 2004 This is pretty cool!
- Walter (3/20) May 16 2004 Yes.
-
Carlos Santander B.
(14/14)
May 16 2004
"Walter"
escribió en el mensaje - Walter (4/7) May 16 2004 good
- Tony (8/13) May 16 2004 The mixin example overrides the definition of "x" within the function
- Walter (3/7) May 17 2004 That rule is probably going to have to go away :-(
- Sean Kelly (6/16) May 17 2004 Looks very promising, but it could also cause quite a bit of unexpected
- Sean Kelly (4/7) May 17 2004 I take it back. The variable overriding feature pretty much takes care
- Norbert Nemec (18/18) May 17 2004 Great work! Apart from my comments about the general problem that the
- Greg Vanore (11/16) May 17 2004 This is a great feature for D.
- Sean Kelly (4/12) May 17 2004 Excellent point. This may make implementing Aspect Oriented Programming...
I have this mostly implemented. It's been based on a lot of your suggestions. The way I did it is, I think, pretty unexplored territory. That means there may be some pretty cool uses for it I've never thought of. Let me know what you think, and if I missed the boat completely <g>. www.digitalmars.com/d/mixin.html
May 16 2004
Walter wrote:I have this mostly implemented. It's been based on a lot of your suggestions. The way I did it is, I think, pretty unexplored territory. That means there may be some pretty cool uses for it I've never thought of. Let me know what you think, and if I missed the boat completely <g>. www.digitalmars.com/d/mixin.htmlWow, this is really nice. -- -Anderson: http://badmama.com.au/~anderson/
May 16 2004
www.digitalmars.com/d/mixin.htmlCoooool!! Is it possible to write something like this? : template Foo() {} class Bar(alias Tmpl) { mixin Tmpl; } Bar!(Foo) x; k.inaba
May 16 2004
"k.inaba" <k.inaba_member pathlink.com> wrote in message news:c879v9$15fg$1 digitaldaemon.com...Yes <g>.www.digitalmars.com/d/mixin.htmlCoooool!! Is it possible to write something like this? : template Foo() {} class Bar(alias Tmpl) { mixin Tmpl; } Bar!(Foo) x;
May 16 2004
Walter wrote:I have this mostly implemented. It's been based on a lot of your suggestions. The way I did it is, I think, pretty unexplored territory. That means there may be some pretty cool uses for it I've never thought of. Let me know what you think, and if I missed the boat completely <g>. www.digitalmars.com/d/mixin.htmlLooks good so far. But two things: First: there is a typo at the top. mixin TemplateIdentifier (! TemplateArgumentList ) ; mixin TemplateIdentifier (! TemplateArgumentList ) MixinIdentifier ; should be (judging from the examples): mixin TemplateIdentifier !( TemplateArgumentList ) ; mixin TemplateIdentifier !( TemplateArgumentList ) MixinIdentifier ; For a moment I thought you'd have to use !( for templates and (! for mixins. I had already started to formulate a flame mail in my head ;). The second thing is a question. Can mixins mix-in other mixins? I.e. template Mix1(T) { void foo(T a) { return 2*a; } } template Mix2(T) { mixin Mix1!(T); void bar(T a) { return foo(a); } } And another thing comes to my mind: can you mixin all kinds of templates? Including specialized ones? Hauke
May 16 2004
"Hauke Duden" <H.NS.Duden gmx.net> wrote in message news:c87gmb$1f8j$1 digitaldaemon.com...First: there is a typo at the top. mixin TemplateIdentifier (! TemplateArgumentList ) ; mixin TemplateIdentifier (! TemplateArgumentList ) MixinIdentifier ; should be (judging from the examples): mixin TemplateIdentifier !( TemplateArgumentList ) ; mixin TemplateIdentifier !( TemplateArgumentList ) MixinIdentifier ; For a moment I thought you'd have to use !( for templates and (! for mixins. I had already started to formulate a flame mail in my head ;).Fixed.The second thing is a question. Can mixins mix-in other mixins? I.e. template Mix1(T) { void foo(T a) { return 2*a; } } template Mix2(T) { mixin Mix1!(T); void bar(T a) { return foo(a); } }Yes!And another thing comes to my mind: can you mixin all kinds of templates? Including specialized ones?Yes, just like for regular template instantiations.
May 16 2004
Walter wrote:I have this mostly implemented. It's been based on a lot of your suggestions. The way I did it is, I think, pretty unexplored territory. That means there may be some pretty cool uses for it I've never thought of. Let me know what you think, and if I missed the boat completely <g>. www.digitalmars.com/d/mixin.htmlOh yeah, forgot to mention: THANKS very much for implementing this! I think this is a kick-ass feature! Hauke
May 16 2004
"Hauke Duden" <H.NS.Duden gmx.net> wrote in message news:c87go0$1f8j$2 digitaldaemon.com...Walter wrote:ThatI have this mostly implemented. It's been based on a lot of your suggestions. The way I did it is, I think, pretty unexplored territory.Letmeans there may be some pretty cool uses for it I've never thought of.You're welcome! Now, I want to see a kick-ass use for this, so I can write a magazine article about it! A use that is cool, not easilly expressed in other languages, and so would highlight the capabilities of D.me know what you think, and if I missed the boat completely <g>. www.digitalmars.com/d/mixin.htmlOh yeah, forgot to mention: THANKS very much for implementing this! I think this is a kick-ass feature!
May 16 2004
Walter wrote:[...] I want to see a kick-ass use for this, so I can write a magazine article about it! A use that is cool, not easilly expressed in other languages, and so would highlight the capabilities of D.Singletons come to mind: singleton.d: template Singleton(T) { private static T _instance; private static bool _deleted = false; public static T get() { assert(!_deleted); if (_instance is null) { _instance = new T(); } return _instance; } public static void destroy() { assert(!_deleted); delete _instance; _instance = null; } } // best global symbol name ever template the(T) { T the() { return T.get(); } } main.d: import singleton; final class Foo { mixin Singleton!(Foo); private this() { ... } } int main() { Foo theFoo = the!(Foo)(); } If you want to do the same in C++, you're pretty much stuck using the preprocessor since you also have to deal with copy constructors and the like. The only catch with the D singleton is that it's up to you to make the constructor private. (this could be alleviated by deferring construction to a create() method, but that's stinky) -- andy
May 16 2004
Would it make sense to put the private this() inside Singleton(T) ? "Andy Friesen" <andy ikagames.com> wrote in message news:c88cc4$2mrb$1 digitaldaemon.com...Walter wrote:[...] I want to see a kick-ass use for this, so I can write a magazine article about it! A use that is cool, not easilly expressed in other languages, and so would highlight the capabilities of D.Singletons come to mind: singleton.d: template Singleton(T) { private static T _instance; private static bool _deleted = false; public static T get() { assert(!_deleted); if (_instance is null) { _instance = new T(); } return _instance; } public static void destroy() { assert(!_deleted); delete _instance; _instance = null; } } // best global symbol name ever template the(T) { T the() { return T.get(); } } main.d: import singleton; final class Foo { mixin Singleton!(Foo); private this() { ... } } int main() { Foo theFoo = the!(Foo)(); } If you want to do the same in C++, you're pretty much stuck using the preprocessor since you also have to deal with copy constructors and the like. The only catch with the D singleton is that it's up to you to make the constructor private. (this could be alleviated by deferring construction to a create() method, but that's stinky) -- andy
May 16 2004
Walter wrote:Would it make sense to put the private this() inside Singleton(T) ?You could, but it's almost completely fire-and-forget as written. Safety vs transparency. :) -- andy
May 16 2004
On Sun, 16 May 2004 12:14:45 -0700, Andy Friesen wrote:Walter wrote:How about putting a class invariant in the mixin that assert(instance is this)? Mike Swieton __ But who prays for Satan? Who, in eighteen centuries, has had the common humanity to pray for the one sinner that needed it the most? - Mark TwainWould it make sense to put the private this() inside Singleton(T) ?You could, but it's almost completely fire-and-forget as written. Safety vs transparency. :)
May 16 2004
Mike Swieton wrote:On Sun, 16 May 2004 12:14:45 -0700, Andy Friesen wrote:You can only have one invariant per class, though. Maybe that restriction needs to be removed, since adding to an invariant is something mixins should be able to do. -- andyWalter wrote:How about putting a class invariant in the mixin that assert(instance is this)?Would it make sense to put the private this() inside Singleton(T) ?You could, but it's almost completely fire-and-forget as written. Safety vs transparency. :)
May 16 2004
Andy Friesen wrote:Singletons come to mind:I'm planning on using mixins in Sinbad for exactly that purpose. (See the proposal for it at dsource.) And possibly quite a few others, such as the event system, which is something that had been giving me dizzy spells before. These things could prove useful to no end... -C. Sauls -Invironz
May 16 2004
Aren't you missing a line, see below. :) Regan. On Sun, 16 May 2004 11:40:09 -0700, Andy Friesen <andy ikagames.com> wrote://Line missing? deleted = true;[...] I want to see a kick-ass use for this, so I can write a magazine article about it! A use that is cool, not easilly expressed in other languages, and so would highlight the capabilities of D.Singletons come to mind: singleton.d: template Singleton(T) { private static T _instance; private static bool _deleted = false; public static T get() { assert(!_deleted); if (_instance is null) { _instance = new T(); } return _instance; } public static void destroy() { assert(!_deleted); delete _instance; _instance = null;} } // best global symbol name ever template the(T) { T the() { return T.get(); } } main.d: import singleton; final class Foo { mixin Singleton!(Foo); private this() { ... } } int main() { Foo theFoo = the!(Foo)(); } If you want to do the same in C++, you're pretty much stuck using the preprocessor since you also have to deal with copy constructors and the like. The only catch with the D singleton is that it's up to you to make the constructor private. (this could be alleviated by deferring construction to a create() method, but that's stinky) -- andy-- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
May 16 2004
Regan Heath wrote:Aren't you missing a line, see below. :) Regan.doh. Yes. The approach is sound, though. -- andy
May 16 2004
On Sun, 16 May 2004 17:54:56 -0700, Andy Friesen <andy ikagames.com> wrote:Regan Heath wrote:Yes, I only mentioned the mistake cos I reckon everyone has copied it and is about to use it! -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/Aren't you missing a line, see below. :) Regan.doh. Yes. The approach is sound, though.
May 16 2004
Walter wrote:"Hauke Duden" <H.NS.Duden gmx.net> wrote in message news:c87go0$1f8j$2 digitaldaemon.com...Well, right now I see mixins as a way to upgrade the language to the power of the C++ preprocessor. Mixins are basically what you'd think of as macros in C++, only as a real language construct with all the subtle advantages of readability, type-safety, etc. But I doubt you'd find something that cannot be done with a macro in C++. The main difference seems to be that the class that uses a mixin can overwrite definitions from the mixin. In C++ you'd have to write an intermediate class to do something like that, but it is still feasible. So I think the main point is that you get the power of macros without the headaches. This is quite an accomplishment if you see how other Maybe I'm missing some other, more revolutionary use, though ;). HaukeWalter wrote:ThatI have this mostly implemented. It's been based on a lot of your suggestions. The way I did it is, I think, pretty unexplored territory.Letmeans there may be some pretty cool uses for it I've never thought of.You're welcome! Now, I want to see a kick-ass use for this, so I can write a magazine article about it! A use that is cool, not easilly expressed in other languages, and so would highlight the capabilities of D.me know what you think, and if I missed the boat completely <g>. www.digitalmars.com/d/mixin.htmlOh yeah, forgot to mention: THANKS very much for implementing this! I think this is a kick-ass feature!
May 16 2004
charset="Windows-1252" Content-Transfer-Encoding: quoted-printable "Walter" <newshound digitalmars.com> wrote in message = news:c889f4$2io2$1 digitaldaemon.com...=20 "Hauke Duden" <H.NS.Duden gmx.net> wrote in message news:c87go0$1f8j$2 digitaldaemon.com...territory.Walter wrote:I have this mostly implemented. It's been based on a lot of your suggestions. The way I did it is, I think, pretty unexplored =thought of.That means there may be some pretty cool uses for it I've never =<g>.Let me know what you think, and if I missed the boat completely =Iwww.digitalmars.com/d/mixin.htmlOh yeah, forgot to mention: THANKS very much for implementing this! =write athink this is a kick-ass feature!=20 You're welcome! Now, I want to see a kick-ass use for this, so I can =magazine article about it! A use that is cool, not easilly expressed =inother languages, and so would highlight the capabilities of D. =20This is GREAT (8^) I personally like the way you have handled scope of mixins, makes = perfect sense to me. BTW you missed one of the (! in the text and can i suggest a minor = grammatical change (in bold); A TemplateMixin can occur in declaration lists of modules, classes, = structs, unions, and as a statement. The TemplateIdentifier refers to a = TemplateDeclaration. If the TemplateDeclaration has no parameters, the = mixin form that has no (!TemplateArgumentList) can be used.=20 Unlike a template instantiation, a template mixin's body is evaluated = within the scope where the mixin appears, not where the template = declaration is defined. It is analogous to cutting and pasting the body = of the template into the location of the mixin. It is useful for = injecting parameterized 'boilerplate' code, as well as for creating = templated nested functions, which is not possible with template = instantiations.=20 As an advocate of class aggregation, I believe your implementation has a = very promising future in this area. I also think that MIXIN's are D's answer to MI, and plan to pursue this = with some examples. Watch this space fred
May 16 2004
charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Thanks, I updated with your fixes.
May 16 2004
that comes to mind for mixins is doing data validation... no code at hand, sorry, but think of doing an IntValidator, DoubleValidator, RangeValidator mixins (which would work kinda like MFC's DDX_Validate) and so on, and just mix 'em into your form class appropriately for each control you'd like to validate...territory.Walter wrote:I have this mostly implemented. It's been based on a lot of your suggestions. The way I did it is, I think, pretty unexploredThataLetmeans there may be some pretty cool uses for it I've never thought of.You're welcome! Now, I want to see a kick-ass use for this, so I can writeme know what you think, and if I missed the boat completely <g>. www.digitalmars.com/d/mixin.htmlOh yeah, forgot to mention: THANKS very much for implementing this! I think this is a kick-ass feature!magazine article about it! A use that is cool, not easilly expressed in other languages, and so would highlight the capabilities of D.
May 17 2004
"Walter" <newshound digitalmars.com> wrote in message news:c889f4$2io2$1 digitaldaemon.com..."Hauke Duden" <H.NS.Duden gmx.net> wrote in message news:c87go0$1f8j$2 digitaldaemon.com...I've got one of those - and the article half planned - as soon as I have an implementation that works. ;)Walter wrote:ThatI have this mostly implemented. It's been based on a lot of your suggestions. The way I did it is, I think, pretty unexplored territory.Letmeans there may be some pretty cool uses for it I've never thought of.You're welcome! Now, I want to see a kick-ass use for this, so I can write a magazine article about it! A use that is cool, not easilly expressed in other languages, and so would highlight the capabilities of D.me know what you think, and if I missed the boat completely <g>. www.digitalmars.com/d/mixin.htmlOh yeah, forgot to mention: THANKS very much for implementing this! I think this is a kick-ass feature!
May 17 2004
so i guess this means that structs can have inheritance now (in a way)? Thats great. In article <c876sh$10r7$1 digitaldaemon.com>, Walter says...I have this mostly implemented. It's been based on a lot of your suggestions. The way I did it is, I think, pretty unexplored territory. That means there may be some pretty cool uses for it I've never thought of. Let me know what you think, and if I missed the boat completely <g>. www.digitalmars.com/d/mixin.html
May 16 2004
Walter wrote:I have this mostly implemented. It's been based on a lot of your suggestions. The way I did it is, I think, pretty unexplored territory. That means there may be some pretty cool uses for it I've never thought of. Let me know what you think, and if I missed the boat completely <g>. www.digitalmars.com/d/mixin.htmlCool! Will something like this work: // helper to make an array "literal" with value semantics // Example: // uintn!(3)(100,200,300) struct InlineArray(T,int N) { static .InlineArray!(T,N) opCall(T x0,...) { .InlineArray!(T,N) res; res.array[] = (&x0)[0..N][]; return res; } mixin CommonInlineArray!(T,N); // add generic N-D members } struct InlineArray(T,int N:2) { // avoid using varargs for safety and speed static .InlineArray!(T,N) opCall(T x0, T x1) { .InlineArray!(T,N) res; res.array[0] = x0; res.array[1] = x1; return res; } T x() { return array[0]; } void x(T val) { array[0] = val; } T y() { return array[1]; } void y(T val) { array[1] = val; } mixin CommonInlineArray!(T,N); // add generic N-D members } // InlineArray members that are independent of dimension private template CommonInlineArray(T,int N) { T[N] array; static .InlineArray!(T,N) opCall(T[N] x) { .InlineArray!(T,N) res; res.array[] = x[]; return res; } T opIndex(int i) { return array[i]; } void opIndex(int i, T val) { array[i] = val; } // todo: arithmetic, cmp, etc } template intn(N) { alias InlineArray!(int,N) uintn; } int main() { intn!(2) p = intn!(2)(4,5); printf("x=%d y=%d array=%p\n", p.x, p[1], p.array); }
May 16 2004
Walter wrote:I have this mostly implemented. It's been based on a lot of your suggestions. The way I did it is, I think, pretty unexplored territory. That means there may be some pretty cool uses for it I've never thought of. Let me know what you think, and if I missed the boat completely <g>. www.digitalmars.com/d/mixin.htmlI was really excited to read the proposal. As usual, you take our ideas and expand and generalize them. However, I'm pretty concerned about the various rules to resolve conflict. I'm particularly scared about the rule that "Mixin has its own scope." These sound very hard to understand, and very hard to read! Can you explain why you defined these rules?
May 16 2004
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message news:c88d0c$2nnf$1 digitaldaemon.com...Walter wrote:ThatI have this mostly implemented. It's been based on a lot of your suggestions. The way I did it is, I think, pretty unexplored territory.Letmeans there may be some pretty cool uses for it I've never thought of.I went around in circles on this for a while - the mixins needed to be overridable in a simple manner. Finally, I decided to use rules analogous to how names come in from an 'import'. In fact, it uses the same code <g>.me know what you think, and if I missed the boat completely <g>. www.digitalmars.com/d/mixin.htmlI was really excited to read the proposal. As usual, you take our ideas and expand and generalize them. However, I'm pretty concerned about the various rules to resolve conflict. I'm particularly scared about the rule that "Mixin has its own scope." These sound very hard to understand, and very hard to read! Can you explain why you defined these rules?
May 16 2004
"Walter" <newshound digitalmars.com> wrote in news:c876sh$10r7$1 digitaldaemon.com:I have this mostly implemented. It's been based on a lot of your suggestions. The way I did it is, I think, pretty unexplored territory. That means there may be some pretty cool uses for it I've never thought of. Let me know what you think, and if I missed the boat completely <g>. www.digitalmars.com/d/mixin.htmlThis is pretty cool! A few question: Can you mixin that same mixin twice ( or more ) if you use a Mixin Identifier? template foo(alias b) { int abc() { return b; } } void test() { int x = 8; int y = 9; mixin Foo!(x) XFoo; mixin Foo!(y) YFoo; assert(XFoo.abc() == 8); assert(YFoo.abc() == 9); }
May 16 2004
"Patrick Down" <pat codemoon.com> wrote in message news:Xns94EB98EDD61ACpatcodemooncom 63.105.9.61...This is pretty cool! A few question: Can you mixin that same mixin twice ( or more ) if you use a Mixin Identifier?Yes.template foo(alias b) { int abc() { return b; } } void test() { int x = 8; int y = 9; mixin Foo!(x) XFoo; mixin Foo!(y) YFoo; assert(XFoo.abc() == 8); assert(YFoo.abc() == 9); }
May 16 2004
"Walter" <newshound digitalmars.com> escribió en el mensaje news:c876sh$10r7$1 digitaldaemon.com | I have this mostly implemented. It's been based on a lot of your | suggestions. The way I did it is, I think, pretty unexplored territory. That | means there may be some pretty cool uses for it I've never thought of. Let | me know what you think, and if I missed the boat completely <g>. | | www.digitalmars.com/d/mixin.html I still fail to see the big picture, but since others have said it's a good thing, then I guess they're right. One question: so a mixin, in some way, would be like an import? ----------------------- Carlos Santander Bernal
May 16 2004
"Carlos Santander B." <carlos8294 msn.com> wrote in message news:c88o3c$5pf$1 digitaldaemon.com...I still fail to see the big picture, but since others have said it's agoodthing, then I guess they're right. One question: so a mixin, in some way, would be like an import?The scoping and overriding rules are the same as for imports.
May 16 2004
The mixin example overrides the definition of "x" within the function "test()". Doesn't this violate the D rule that a symbol can't be multiply defined within a function? Tony "Walter" <newshound digitalmars.com> wrote in message news:c876sh$10r7$1 digitaldaemon.com...I have this mostly implemented. It's been based on a lot of your suggestions. The way I did it is, I think, pretty unexplored territory.Thatmeans there may be some pretty cool uses for it I've never thought of. Let me know what you think, and if I missed the boat completely <g>. www.digitalmars.com/d/mixin.html
May 16 2004
"Tony" <talktotony email.com> wrote in message news:c89gd4$19nf$1 digitaldaemon.com...The mixin example overrides the definition of "x" within the function "test()". Doesn't this violate the D rule that a symbol can't be multiply defined within a function?That rule is probably going to have to go away :-(
May 17 2004
Walter wrote:"Tony" <talktotony email.com> wrote in message news:c89gd4$19nf$1 digitaldaemon.com...Looks very promising, but it could also cause quite a bit of unexpected behavior as the implementation details of a mixin can affect the calling function. I don't suppose there are scope resolution operators to allow the caller to specify which instance of x he wants to access? SeanThe mixin example overrides the definition of "x" within the function "test()". Doesn't this violate the D rule that a symbol can't be multiply defined within a function?That rule is probably going to have to go away :-(
May 17 2004
Sean Kelly wrote:Looks very promising, but it could also cause quite a bit of unexpected behavior as the implementation details of a mixin can affect the calling function.I take it back. The variable overriding feature pretty much takes care of this. Sean
May 17 2004
Great work! Apart from my comments about the general problem that the untyped compile-time language of D will probably prove to be extremely hard to debug, I really like this absolutely powerful concept of mixins. Anybody who knows Sather will realize, that mixins contain the complete concept of implementation inheritance! To those unfamiliar with Sather: in that highly interesting language, inheritance is completely split up into interface inheritance and implementation inheritance. Interface inheritance is just what we have in D already. Implementation inheritance is just that kind of parameterized cut-and-paste operation that mixins allow. Taking both together, it becomes obvious, that direkt inheritance is not necessary at all any more! All the problems of multiple-inheritance in C++ come from binding together the inheritance of the class interface and the implementation of its routines. As you can easily see in D: neither interfaces nor mixins have problems with multiple inheritance (resp. inclusion of several mixins into one class definition) Conclusion: multiple interface inheritance and mixins taken together are a complete replacement for the multiple inheritace that was dropped!
May 17 2004
This is a great feature for D. Coming from an enterprise software background, I can tell you that it may have a lot of use for cross-cutting concerns. OOP generally puts tight coupling between a system-level concern and the business logic of an application, but with mixins, you could theoretically define a solution to a problem and apply it generically across business classes. I'll play more and hopefully post something demonstrating some aspect-oriented programming techniques with D and mixins. "Walter" <newshound digitalmars.com> wrote in message news:c876sh$10r7$1 digitaldaemon.com...I have this mostly implemented. It's been based on a lot of your suggestions. The way I did it is, I think, pretty unexplored territory.Thatmeans there may be some pretty cool uses for it I've never thought of. Let me know what you think, and if I missed the boat completely <g>. www.digitalmars.com/d/mixin.html
May 17 2004
Greg Vanore wrote:Coming from an enterprise software background, I can tell you that it may have a lot of use for cross-cutting concerns. OOP generally puts tight coupling between a system-level concern and the business logic of an application, but with mixins, you could theoretically define a solution to a problem and apply it generically across business classes. I'll play more and hopefully post something demonstrating some aspect-oriented programming techniques with D and mixins.Excellent point. This may make implementing Aspect Oriented Programming in D fairly easy, which is a technique that IMO has tremendous potential. Sean
May 17 2004