Berkeley CSUA MOTD:Entry 12770
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/25 [General] UID:1000 Activity:popular
5/25    

2004/3/19-20 [Computer/SW/Languages/Java, Computer/SW/Languages/Python] UID:12770 Activity:nil
3/19    Can anyone provide a reference to the origin of the term "mixin"
        (in programming contexts)? Thanks.
        \_ http://c2.com/cgi/wiki?MixIn
           http://noframes.linuxjournal.com/lj-issues/issue84/4540.html
2025/05/25 [General] UID:1000 Activity:popular
5/25    

You may also be interested in these entries...
2013/5/1-18 [Computer/SW/Languages/Java, Computer/Theory] UID:54669 Activity:nil
5/1     What's the difference between CS and Computer Engineering?
        http://holykaw.alltop.com/top-ten-paying-degrees-for-college-graduates
        \_ One is science and the other is engineering.
        \_ From http://en.wikiquote.org/wiki/Computer_science
           'A folkloric quotation ... states that "computer science is no more
           about computers than astronomy is about telescopes."  The design
	...
2012/12/4-18 [Computer/SW/Languages/Java] UID:54544 Activity:nil
12/4    Holy cow, everyone around me in Silicon Valley is way beyond
        middle class according to Chinni's definition:
        http://en.wikipedia.org/wiki/American_middle_class
        \_ Let's set our goals higher:
           http://en.wikipedia.org/wiki/Upper_middle_class_in_the_United_States
           \_ How about this one?
	...
2012/10/29-12/4 [Science/Disaster, Computer/SW/Languages/Java, Politics/Domestic/President/Bush] UID:54516 Activity:nil
10/29   Go Away Sandy.
        \_ Sorry, Coursera is performing preventive maintenance for this
           class site ahead of Hurricane Sandy. Please check back in 15 minutes.
           class site ahead of Hurricane Sandy. Please check back in 15
           minutes.
        \_ Bitch.
	...
2012/1/18-3/3 [Computer/SW/Languages/Java, Finance/Investment] UID:54290 Activity:nil
1/18    I own a bunch of NFLX stocks bought at several different periods
        (from high $200 all the way down to $80). I dumped a few and
        still have a few. Why the hell is Reid Hastings still making
        $500,000/year? How do I join the pending NFLX Class Action
        Lawsuit?
        \_ Why would you buy stock in a company run by a narcissistic
	...
2013/4/9-5/18 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Apps, Computer/SW/Languages/Perl] UID:54650 Activity:nil
4/04    Is there a good way to diff 2 files that consist of columns of
        floating point numbers, such that it only tells me if there's a
        difference if the numbers on a given line differ by at least a given
        ratio?  Say, 1%?
        \_ Use Excel.
           1. Open foo.txt in Excel.  It should convert all numbers to cells in
	...
2012/12/18-2013/1/24 [Computer/SW/Languages/Perl] UID:54561 Activity:nil
12/18   Happy 25th birthday Perl, and FUCK YOU Larry Wall for fucking up
        the computer science formalism that sets back compilers development
        back for at least a decade:
        http://techcrunch.com/2012/12/18/print-happy-25th-birthday-perl
        \_ I tried to learn Perl but was scared away by it.  Maybe scripting
           lanauages have to be like that in order to work well?
	...
2011/12/23-2012/2/6 [Computer/SW/Languages/Python] UID:54272 Activity:nil
12/23   In Python, why is it that '好'=='\xe5\xa5\xbd' but
        u'好'!='\xe5\xa5\xbd' ? I'm really baffled. What
        is the encoding of '\xe5\xa5\xbd'?
        \_ '好' means '\xe5\xa5\xbd', which is just a string of bytes; it has
           length 3.  Python doesn't know what encoding it's in.  u'好' means
           u'\u597d', which is a string of Unicode characters; it has length 1,
	...
2011/4/16-7/13 [Computer/SW/Languages/Python] UID:54086 Activity:nil
4/16    Whoa, I just heard that MIT discontinued 6.001 (classic scheme)
        to 6.01. In fact, 6.00, 6.01 and 6.02 all use Python. What the
        hell? What has the world become? It's a sad sad day. SICP forever!
        \_ old story, they've ditched that shitty book and lang for a while.
        \_ I used to think scheme was cool, then I saw Ka Ping Yee's
           "Beautiful Code" class aka 61a in python, and converted.
	...
2011/2/24-4/20 [Computer/SW/Languages/Java] UID:54048 Activity:nil
2/24    Go Programming Language.  Anyone here use it?  It kind of
        reminds me of java-meets python, and well, that is fitting given it's
        a GOOG product.  What is so special about it?
        \_ as I understand it, it's a suitable OOP-y systems language with more
           structure than C, less complexity than C++, and less overhead than
           Java/Python.
	...
2011/3/31-4/20 [Computer/SW/Languages/Python] UID:54070 Activity:nil
3/20    Has anyone here had success in using python 3.0?  Any gotchas
        to worry about? I've got an entire set of apps in python 2.x
        and am wondering if it's worth it to upgrade?
	...
2010/8/8-9/7 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Languages/Web] UID:53914 Activity:nil
8/8     Trying to make a list of interesting features languages have
        touted as this whole PL field comes around, trying to see if they
        have basis in the culture of the time: feel free to add some/dispute
        1970 C, "portability"
        1980 C++, classes, oop, iterators, streams, functors, templates
             expert systems
	...
2010/8/12-9/7 [Computer/SW/Languages/Perl] UID:53922 Activity:nil
8/12    Ruby coders, do you mostly DIY your stuff or use the ruby libs out
        there?   How is their quality compared to other libs you have used
        for other langs?  Thx.
        \_ I use Ruby for hobby stuff, etc.  I use libraries for system stuff
           (web access, process, etc.) but that's about it.  Perl libraries are
           much better/more complete.  I assume because of the maturity and
	...
Cache (3272 bytes)
c2.com/cgi/wiki?MixIn
Mix In Mix In MixIn programming is a style of software development where units of functionality are created in a class and then mixed in with other classes. A mixin class is a parent class that is inherited from - but not as a means of specialization. Typically, the mixin will export services to a child class, but no semantics will be implied about the child being a kind of the parent. A MixIn is also called an AbstractSubclass since MixIn can provide other services based on the services the original class provides. Mixins are controversial because the prescribed way of providing such services is by association. However, they are useful because inheritance places the services within the child itself. For this reason they are commonly found in windows class libraries where there is a need for certain features to be generalized for mixing in later. Actually Mixins are only controversial because people try to use them in languages with no support for them. Imagine you have vanilla ice where you can add in different stuff. Parts of the Lisp Machine operating system were programmed using mixins. An example is the window system, where you can mixin borders-mixins into window classes. So it does not mixin the borders itself, but adds the feature that the window has borders. In Flavors the classes slots are extended AND and that is the big AND the methods get extended OR overwritten, too. Well, in this case the ordering is not important for the CLOS example. In CLOS one could also use a method combination, where the results of all methods get collected. So, you would define a bunch of WIDTH methods for the various elements that contribute to the window width and have them added by the method combination. The word mixin comes from Steves Ice Cream, a favorite ice cream shop of MIT students located in Sommerville, MA in the late 70s. Steves made its own very rich ice cream in a motorized old fashioned ice cream maker in the window of the shop. Sometimes the line for an ice cream cone was out the door and down the block! You would order a cone or dish, and specify the base flavor and any mixins you wanted. The person behind the counter would plop your scoop of ice cream on a marble slab, dump a spoonful of mixins on top, and knead the two together, using two metal spatulas. My personal favorite was chocolate ice cream with crushed oreo cookies mixed in. The use of the :before after :after methods that are part of the standard MethodCombination makes this a handy pattern in the CommonLispObjectSystem . In addition to the CommonLispObjectSystem , the XoTclExtension for the ToolCommandLanguage has good support for mixins. Also see MixinsForPython CategoryPolymorphism It has become doubtful as to whether MixIn techniques can be called polymorphism. According to NonPolymorphicInheritance , using a MixIn does not entail delegation see WhatIsDelegation , and so lacking the requisite indirection, does not have polymorphic behavior. Delegation does not imply polymorphism though in some cases it does. See DifferentStylesOfDelegation This is true, but delegation indirection PolyMorphism . Im not sure I grok what you mean by indirection here-polymorphism is usually defined in terms of type substitutability, however that is implemented.
Cache (8124 bytes)
noframes.linuxjournal.com/lj-issues/issue84/4540.html -> www.linuxjournal.com/article.php?sid=4540
An explanation of the mix-in programming style as applied in Python. Mix-in programming is a style of software development where units of functionality are created in a class and then mixed in with other classes. This might sound like simple inheritance at first, but a mix-in differs from a traditional class in one or more of the following ways. Often a mix-in is not the primary superclass of any given class, does not care what class it is used with, is used with many classes scattered throughout the class hierarchy and is introduced dynamically at runtime. There are several reasons to use mix-ins: they extend existing classes in new areas without having to edit, maintain or merge with their source code; So while mix-ins are not a distinct technical feature of Python, the benefits of this technique are worth studying. Python provides an ideal language for mix-in development because it supports multiple inheritance, supports full-dynamic binding and allows dynamic changes to classes. Before we dive into Python, let me admit that mix-ins are old hat. The first time I saw mix-in programming by that name was when reviewing the now-defunct Taligent Project, known for its Pink operating system and CommonPoint application framework. However, since C does not support language feature 2, full-dynamic binding, or language feature 3, dynamic changes at runtime, Im not surprised that the approach didnt bring to fruition all its inventors had hoped for. I have also seen another instance of mix-in programming under a different name. Objective-C has a nifty language feature called categories that allows you to add and replace methods of existing classes, even without access to their source code. This is great for repairing existing system classes and extending their capabilities. Also, combined with an ability to load libraries dynamically, categories are quite effective in improving the structure of applications and reducing code. The grapevine informs me that Symbolics object-oriented Flavors system is most likely the earliest appearance of bona fide mix-ins. The designers were inspired by Steves Ice Cream Parlor in Cambridge, Massachusetts where customers started with a basic flavor of ice cream vanilla, chocolate, etc. It continues to work even if the class inheritance or method definitions are altered at runtime. One thing to keep in mind is the order of searching with regard to multiple inheritance. The search order goes from left to right through the base classes, and for any given base class, goes deep into its ancestor classes. When you create mix-ins, keep in mind the potential for method names to clash. By creating distinct mix-ins with well-named methods you can generally avoid any surprises. Most Python things, whether they are lists, dictionaries, classes or instances, have a set of accessible attributes. Python classes have an attribute named __bases__, which is a tuple of their base classes. In the following session with the Python interactive interpreter seen in Listing 1, we create two classes and then later change the inheritance. Installing a Mix-in Dynamically The first statement above changes the base classes of Person. By using as opposed to we avoid accidentally removing existing base classes, especially if a future version of the code makes Person inherit from another class. Also, the funny looking expression, Friendly, , specifies a tuple that would normally simply be enclosed in parenthesis. However, while Python readily recognizes <IfCourier>x,y<I$f$> as a tuple of two elements, it recognizes <IfCourier>x<I$f$> as a parenthesized expression. MySQLdb Cursor Mix-ins The most straightforward way to apply mix-ins is at design time within the construction of a module. One of the more famous third-party modules for Python, MySQLdb, does exactly this. The design of this method reflects the fact that Python objects often provide information through both attributes and methods. A Mix-in for Uniform Value Access A useful application of this mix-in is to implement generic code for writing logs see Listing 3. Applying the NamedValueAccessible Mix-in for Logging By simply adding new keys to the logColumns method, the log can be expanded without having to modify the code that generates it, which is found in logEntry . More importantly, you can imagine that logColumns could read its list of fields from a simple configuration file. The transaction object itself is free to provide the given values via either methods or attributes, due to the flexibility of the valueForKey method. Making mix-ins flexible increases their utility and is an art that can be developed over time. Mixing It in after the Fact So far we have seen examples of using mix-ins during the construction of classes. However, Pythons dynamic nature also allows us to mix in functionality at runtime. The simplest technique for doing so is to modify the base classes of the given class, as described earlier. In the construction of internet applications, keeping domain classes separate from interface classes is generally a good idea. Domain classes represent the concepts, data and operations of a specific application. They are independent of operating system, user interface, database, etc. Some writers refer to domain objects as business objects, model objects or problem space objects. Keeping the domain and interface separate makes sense for various reasons. An individual focus is created for two key areas that are largely independent: What is the subject material of the problem? New interfaces can be constructed without modifying or rewriting the domain classes. Domain classes for a story publishing system might include Story, Author and Site. These classes contain essential attributes such as title, body, name, e-mail, etc. Existing subclasses of Story are in no way affected by simply creating a new Story class or subclass. But a dynamic mix-in for Story will also affect Editorial, Feature and Column. That is why many times the static approach does not work in practice, thereby making the dynamic approach not only clever, but necessary. Also, consider the case where Story objects are created in parts of the code where Story is hard-coded. In this situation, creating subclasses of Story will have no effect on the code that ignores them. One warning regarding dynamic mix-ins: they can change the behavior of existing objects because they change the classes of those objects. This could lead to unpredictable results, as most classes are not designed with that type of change in mind. The safe way to use dynamic mix-ins is to install them when the application first starts, before any objects are created. User import User MixInUser, UserMixIn One solution is to bind the mix-ins to their target classes by name and have the application install these at startup. For example, all mix-ins could be named directly after the class they modify and put into a MixIns/ directory. Detecting and Installing Mix-ins Named after Their Classes Additional Uses While its fun to explore more sophisticated versions of the MixIn function, the most important key is the ability to apply them in order to improve your software. Here are some additional uses to stimulate your imagination: A class could augment itself with a mix-in after reading a configuration file. For example, a web server class could mix in Threading or Forking depending on how its configured. A program could provide for plug-ins: software packages that are located and loaded at launch time to enhance the program. Those who implement plug-ins could make use of MixIn to enhance core program classes. Summary Mix-ins are great for improving modularity and enhancing existing classes without having to get intimate with their source code. This in turn supports other design paradigms, like separation of domain and interface, dynamic configuration and plug-ins. Pythons inherent support for multiple inheritance, dynamic binding and dynamic changes to classes enables a very powerful technique. As you continue to write Python code, consider ways in which mix-ins can enhance your software.