Questions Concepts
GitHub icon


Mixins - language feature

< >
Example from Python, Cython:
# class EssentialFunctioner(LoggerMixin, object):
Example from Ruby:
module A def a1 end def a2 end end module B def b1 end def b2 end end class Sample include A include B def s1 end end samp = samp.a1 samp.a2 samp.b1
// class SmartObject implements Disposable, Activatable { } // Note: still need to do some runtime ops to make that work.
Example from Julia:
# Including the same code in different modules provides mixin-like behavior. module Normal include("mycode.jl") end module Testing include("safe_operators.jl") include("mycode.jl") end
Example from Racket:
(mixin (interface-expr ...) (interface-expr ...) class-clause ...)
Example from Sass:
@mixin reset-list margin: 0 padding: 0 list-style: none @mixin horizontal-list @include reset-list li display: inline-block margin: left: -2px right: 2em nav ul @include horizontal-list
Example from Xtext:
grammar org.example.domainmodel.Domainmodel with org.eclipse.xtext.common.Terminals
Example from SCSS:
@mixin reset-list { margin: 0; padding: 0; list-style: none; } @mixin horizontal-list { @include reset-list; li { display: inline-block; margin: { left: -2px; right: 2em; } } } nav ul { @include horizontal-list; }

Languages with Mixins include Python, Ruby, TypeScript, Julia, Racket, Sass, Cython, Xtext, SCSS, Static Typescript

Languages without Mixins include CSS

This question asks: Does the language allow including methods from a class without inheriting from that class?

Read more about Mixins on the web: 1.

HTML of this page generated by Features.ts

View source

- Build the next great programming language Search Add Language Features Creators Resources About Blog Acknowledgements Queries Stats Sponsor Traffic Traffic Today Day 305 Logout