www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Blog post : OOP composition with mixins

reply "Dicebot" <public dicebot.lv> writes:
Rough summary of the talk I have given for recent Berlin D meetup 
event:
https://blog.dicebot.lv/posts/2015/08/OOP_composition_with_mixins
Aug 24 2015
next sibling parent reply "Atila Neves" <atila.neves gmail.com> writes:
On Monday, 24 August 2015 at 11:10:16 UTC, Dicebot wrote:
 Rough summary of the talk I have given for recent Berlin D 
 meetup event:
 https://blog.dicebot.lv/posts/2015/08/OOP_composition_with_mixins
Nice. I've only just started exploring code reuse with template mixins, and used it to great effect in my last project. Blogs like this are useful since there aren't many examples in other languages (Ruby modules come to mind). Atila
Aug 24 2015
parent reply "Abdulhaq" <alynch4047 gmail.com> writes:
On Monday, 24 August 2015 at 13:28:23 UTC, Atila Neves wrote:
 On Monday, 24 August 2015 at 11:10:16 UTC, Dicebot wrote:
 Rough summary of the talk I have given for recent Berlin D 
 meetup event:
 https://blog.dicebot.lv/posts/2015/08/OOP_composition_with_mixins
Nice. I've only just started exploring code reuse with template mixins, and used it to great effect in my last project. Blogs like this are useful since there aren't many examples in other languages (Ruby modules come to mind). Atila
Inheritance certainly is 'the base class of all evil'. I have a theory that the reason inheritance is so overused in OOP languages lies in the way it is taught - the OOP aspects cover much of the syntax of the language and hence much teaching material revolves around inheritance. This makes the student believe that inheritance is therefore the 'right way' to proceed. Many years of pain have, however, taught me to avoid inheritance and to prefer composition - even/especially when using e.g. Java.
Aug 31 2015
parent =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench saphirion.com> writes:
On 2015-08-31 14:20:23 +0000, Abdulhaq said:

 Inheritance certainly is 'the base class of all evil'. I have a theory 
 that the reason inheritance is so overused in OOP languages lies in the 
 way it is taught - the OOP aspects cover much of the syntax of the 
 language and hence much teaching material revolves around inheritance. 
 This makes the student believe that inheritance is therefore the 'right 
 way' to proceed.
I think what's missing is, that inheritance should be used with a type-system view in mind. It makes sense to model "typed things" but not to model functionallity / re-using of functionallity. This is much bettern done with a concept like mixins. And mixing both is a very powerful way to model complex system. You "just" need to know when to use one or the other.
  Many years of pain have, however, taught me to avoid inheritance and 
 to prefer composition - even/especially when using e.g. Java.
Because all those OOP languages are to dogmatic about it's use. C++ is free, but is missing (not sure if still) the template and mixin power of D. -- Robert M. Münch http://www.saphirion.com smarter | better | faster
Aug 31 2015
prev sibling next sibling parent reply "Dejan Lekic" <dejan.lekic gmail.com> writes:
Good article.

However, composition also has some drawbacks and they should be 
explained.

Speaking about Java and inheritance, and popular believe it is 
overused - Yes, maybe it is, but Java does not have language 
features D has, and it should not be blamed for that. Interesting 
article for those looking for "more serious" criticism of Java 
and inheritance: 
https://www.cs.auckland.ac.nz/~ewan/qualitas/studies/inheritance/TemperoYangNobleECOOP2013-pre.pdf

What I think D community would benefit from would be a series of 
"Idiomatic D" articles.
Aug 24 2015
parent "thedeemon" <dlang thedeemon.com> writes:
On Monday, 24 August 2015 at 16:21:04 UTC, Dejan Lekic wrote:

 What I think D community would benefit from would be a series 
 of "Idiomatic D" articles.
This collection of short pieces comes to mind: http://p0nce.github.io/d-idioms/
Aug 25 2015
prev sibling next sibling parent reply "jmh530" <john.michael.hall gmail.com> writes:
On Monday, 24 August 2015 at 11:10:16 UTC, Dicebot wrote:
 Rough summary of the talk I have given for recent Berlin D 
 meetup event:
 https://blog.dicebot.lv/posts/2015/08/OOP_composition_with_mixins
It seems like mixin templates can be used like alias this, but mixin templates are more general. When would I want to use alias this instead of a mixin template?
Aug 31 2015
parent "Dicebot" <public dicebot.lv> writes:
On Monday, 31 August 2015 at 14:44:27 UTC, jmh530 wrote:
 On Monday, 24 August 2015 at 11:10:16 UTC, Dicebot wrote:
 Rough summary of the talk I have given for recent Berlin D 
 meetup event:
 https://blog.dicebot.lv/posts/2015/08/OOP_composition_with_mixins
It seems like mixin templates can be used like alias this, but mixin templates are more general. When would I want to use alias this instead of a mixin template?
`alias this` is more suitable for cases when reused functionality is self-contained and useful separately. It is closer in spirit to inheritance because you take existing entity and provide its API as part of new aggregate. As a simple rule of a thumb, I'd go for `alias this` approach when mixed in functionality does not need to know anything about surrounding context (== has no template parameters). mixin template feels more convenient for small configurable building blocks that don't have well-defined semantics without any specific context. Important difference between `alias this` and `mixin` is that `alias this` allows implicit casting to the aliased field type - which can be both merit and drawback depending on design intentions.
Aug 31 2015
prev sibling next sibling parent reply =?UTF-8?B?Ikx1w61z?= Marques" <luis luismarques.eu> writes:
On Monday, 24 August 2015 at 11:10:16 UTC, Dicebot wrote:
 Rough summary of the talk I have given for recent Berlin D 
 meetup event:
 https://blog.dicebot.lv/posts/2015/08/OOP_composition_with_mixins
I'm having trouble resolving that DNS name.
Sep 01 2015
parent reply "Dicebot" <public dicebot.lv> writes:
On Tuesday, 1 September 2015 at 10:18:08 UTC, LuĂ­s Marques wrote:
 On Monday, 24 August 2015 at 11:10:16 UTC, Dicebot wrote:
 Rough summary of the talk I have given for recent Berlin D 
 meetup event:
 https://blog.dicebot.lv/posts/2015/08/OOP_composition_with_mixins
I'm having trouble resolving that DNS name.
Technical server issues, should be back now.
Sep 01 2015
parent reply "cym13" <cpicard openmailbox.org> writes:
On Tuesday, 1 September 2015 at 11:36:49 UTC, Dicebot wrote:
 On Tuesday, 1 September 2015 at 10:18:08 UTC, LuĂ­s Marques 
 wrote:
 On Monday, 24 August 2015 at 11:10:16 UTC, Dicebot wrote:
 Rough summary of the talk I have given for recent Berlin D 
 meetup event:
 https://blog.dicebot.lv/posts/2015/08/OOP_composition_with_mixins
I'm having trouble resolving that DNS name.
Technical server issues, should be back now.
BTW, a bit HS but in your article about Rust (https://blog.dicebot.lv/posts/2015/01/thoughts_about_rust_from_d_programmer) there is a “</code>” lying in the first example.
Sep 01 2015
parent "Dicebot" <public dicebot.lv> writes:
On Tuesday, 1 September 2015 at 13:44:15 UTC, cym13 wrote:
 BTW, a bit HS but in your article about Rust 
 (https://blog.dicebot.lv/posts/2015/01/thoughts_about_rust_from_d_programmer)
there is a “</code>” lying in the first example.
Thanks, fixed.
Sep 01 2015
prev sibling parent reply "Meta" <jared771 gmail.com> writes:
On Monday, 24 August 2015 at 11:10:16 UTC, Dicebot wrote:
 Rough summary of the talk I have given for recent Berlin D 
 meetup event:
 https://blog.dicebot.lv/posts/2015/08/OOP_composition_with_mixins
Are you planning on submitting this article to Reddit/Hacker News?
Sep 01 2015
parent reply "Dicebot" <public dicebot.lv> writes:
On Tuesday, 1 September 2015 at 14:11:44 UTC, Meta wrote:
 On Monday, 24 August 2015 at 11:10:16 UTC, Dicebot wrote:
 Rough summary of the talk I have given for recent Berlin D 
 meetup event:
 https://blog.dicebot.lv/posts/2015/08/OOP_composition_with_mixins
Are you planning on submitting this article to Reddit/Hacker News?
There is something wrong about submitting own articles into aggregators :) Feel free to do so if you want to.
Sep 01 2015
parent "Meta" <jared771 gmail.com> writes:
On Tuesday, 1 September 2015 at 14:32:11 UTC, Dicebot wrote:
 On Tuesday, 1 September 2015 at 14:11:44 UTC, Meta wrote:
 On Monday, 24 August 2015 at 11:10:16 UTC, Dicebot wrote:
 Rough summary of the talk I have given for recent Berlin D 
 meetup event:
 https://blog.dicebot.lv/posts/2015/08/OOP_composition_with_mixins
Are you planning on submitting this article to Reddit/Hacker News?
There is something wrong about submitting own articles into aggregators :) Feel free to do so if you want to.
Sounds good to me. https://www.reddit.com/r/programming/comments/3j8bi2/oop_composition_with_mixins_in_the_d_programming/
Sep 01 2015