Jump to content

Talk:Mixin

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 64.125.109.66 (talk) at 17:49, 26 April 2010 (→‎Compromises: new section). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

WikiProject iconComputing Start‑class
WikiProject iconThis article is within the scope of WikiProject Computing, a collaborative effort to improve the coverage of computers, computing, and information technology on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
StartThis article has been rated as Start-class on Wikipedia's content assessment scale.
???This article has not yet received a rating on the project's importance scale.
WikiProject iconComputer science Start‑class High‑importance
WikiProject iconThis article is within the scope of WikiProject Computer science, a collaborative effort to improve the coverage of Computer science related articles on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
StartThis article has been rated as Start-class on Wikipedia's content assessment scale.
HighThis article has been rated as High-importance on the project's importance scale.
Things you can help WikiProject Computer science with:

Confusing analogy

The bowl and ingredient analogy is confusing—Preceding unsigned comment added by 141.154.250.176 (talkcontribs) 14:53, 2 June 2004

Are mixins bad?

I always wondered: are Mixin's "bad"? I'm sure the proper answer is that they're useful in some scenarios, but detrimental in others. What should I look out for? What are similar paradigms that get mistakenly used as Mixin's? I don't want to suffer from Golden hammer syndrome, if there's something that answers the problem better... --Eddie Parker 13:19, 2 May 2005 (UTC)[reply]

Flavors

Link to Flavors needs a substantive page.—Preceding unsigned comment added by 217.43.207.44 (talkcontribs) 22:42, 18 June 2005

Error in "Comentary"

Inheritance can indeed be used to refactor common behavior, so mixins are just another way of getting the same functionality, AFAIK. (*)

Well, CLOS generic functions allow multiple dispatching, but I don't know if this has something to do with mixins... Maybe it cannot be donne (except for the trick in Visitor) with the other sintax?

(*) Mixins add the benefit of being suitable for some aspect-oriented programming. This is because they can refactor methods from classes that have nothing in common (so it would be a bad practice to make them inherit from a common base). This is also true with the very similar way of ArtScript for defining class attributes. Anyway I wonder wether the benefits of AOP which mixins bring couldn't be reached using multiple inheritance...

--USer:Euyyn

Example

Could someone familiar with this concept provide a simple code example? John (Jwy) 18:22, 1 April 2006 (UTC)[reply]

I added one for python. Cburnett 03:35, 26 June 2007 (UTC)[reply]

Misleading and incomplete

I've just accidentically stumbled into this article, and I get the severe feeling that it is misleading and incomplete. Most importantly it doesn't really give substantial information, what a mixin is. Then, it is too fixated on specific programming languages. Using mixins is a a programming style, which by and large can be used in nearly every programming language. Just google for Mixin+C++ to get a hint. E.g. Smaragdakis and Batory.

I only have time for this notice right now, but I'll have a try at the article in the future.

Pjacobi 12:30, 12 April 2006 (UTC)[reply]

Definition and implementation - Missing Javascript

Given the popularity of Javascript, it should probably get added to the list of languages that use Mixin for object creation. In Javascript, you define the class and add the methods afterwards. You can add methods new at runtime. data64 17:59, 24 September 2006 (UTC)[reply]

Um, javascript doesn't have classes. The best you can do is is copy in methods from another object but you have to do that manually. Cburnett 03:22, 26 June 2007 (UTC)[reply]

PHP and ColdFusion

I removed PHP. How can you have mixins in PHP when PHP only has single inheritance? That gives you no room to "mix in" the mixin class. The best you can do is declare a class as abstract and inherit from there, but how can that be a "mixin"? Cburnett 03:20, 26 June 2007 (UTC)[reply]


I also removed ColdFusion. Again, like PHP, it does not have multiple inheritances so how can mixins work? Cburnett 23:35, 27 June 2007 (UTC)[reply]

Did you know that using of mixins is also possible in languages that support only single inheritance? Take a look at Ruby or Java. Ruby uses modules for that purpose (http://www.rubycentral.com/pickaxe/tut_modules.html) and Java leverages the power of Aspect-oriented programming (as someone noticed in Commentary section). —The preceding unsigned comment was added by 83.27.165.149 (talkcontribs).
That link gave me a 'file not found' error. Can you give an example of how to use a mixin with PHP to achieve something like my python example (I know, PHP doesn't have threads but something analogous would be fine)? Cburnett 03:52, 9 July 2007 (UTC)[reply]
Thanks, I have corrected ruby link. Unfortunately I didn't know PHP at all (look at http://www.advogato.org/article/470.html). I just pointed out that usage of mixins is also possible in languages that support single inheritance only. —The preceding unsigned comment was added by 89.79.58.109 (talkcontribs).
I appreciate the links. The PHP example is an ugly, ugly hack. PHP does not support mixins and the method used in your advogato.org link is dynamically creating classes via eval() calls. The Ruby example is a step in the right direction (classes are not dynamically created). My qualm with that method is that the mixin is no longer a class like this article defines a mixin as ("a mixin is a class"). It's merely including functions that pretend they are in a class. The WhoAmI function references self when it is clearly not in a class (in this way it is a true mixin because it definitely cannot stand alone).
At the end of the day, I don't have a strong problem including Ruby (perhaps some of the other languages listed also do "mixins" in a similar way) but I do with PHP. In PHP, functions are not first class objects therefore your only route is to dynamically create classes to work around the languages inability to do it the "Ruby way" or a more literal way like Python.
I would like to see the list split up into "the real way with multiple inheritances of classes" and "the ruby include kind of way". Cburnett 13:39, 9 July 2007 (UTC)[reply]

This but not that

How can a programmer in mixin enabled programming languages decide which methods/attributes of a superclass shall be mixed in to the to developed subclass and which not? --Abdull (talk) 15:57, 8 February 2008 (UTC)[reply]

The exact mechanics depend on the language. Mixin is more like a design pattern. You have to decide which functions perform what parts of your task and then you implement just certain functions differently to get different behavior.
In the python example the ThreadingMixIn class implements the process_request method. This method creates the new thread that handles the rest of the request in that new thread. The ForkingMixIn, instead, forks another process to handle the rest of the request. Cburnett (talk) 19:27, 8 February 2008 (UTC)[reply]

Compromises

"However, mixins introduce their own set of compromises."

What compromises? What compromises of multiple inheritance do mixins avoid?

64.125.109.66 (talk) 17:49, 26 April 2010 (UTC)[reply]