Is it possible to implement mixins in C#?

It really depends on what you mean by “mixin” – everyone seems to have a slightly different idea. The kind of mixin I’d like to see (but which isn’t available in C#) is making implementation-through-composition simple: public class Mixin : ISomeInterface { private SomeImplementation impl implements ISomeInterface; public void OneMethod() { // Specialise just this … Read more

Using variables for CSS properties in Sass

You need to use interpolation (eg. #{$var}) on your variable in order for Sass to treat it as a CSS property. Without it, you’re just performing variable assignment. @mixin w_fluid($property_name, $w_element, $w_parent:16) { #{$property_name}: percentage(($w_element / $w_parent)); }

What is C++ Mixin-Style?

Mixins are a concept from Lisp. A good explanation from Dr. Dobbs: A mixin is a fragment of a class in the sense that it is intended to be composed with other classes or mixins. […] The difference between a regular, stand-alone class (such as Person) and a mixin is that a mixin models some … Read more

LessCss dynamic variables based on ancestor class

Well, no, you can’t use class name to determine a variable or a return value. So it’s usually done in reverse, for example like this: @brand-default: #649d84; @brand-africa: #df6f20; @brand-nz: #444444; h1 { .brand-colors(); } h2 { .brand-colors(background-color); } .brand-colors(@property: color) { .color(default); .color(africa); .color(nz); .color(@name) { .brand-@{name} & { @value: ‘brand-@{name}’; @{property}: @@value; } … Read more

@import in @if statement in Sass

It’s one of those things that’s just not allowed. The only thing you can do is turn those imports into mixins (import the file outside the @if and call the mixin where appropriate). Clarification: _partial.scss @mixin partial { .test { color: red } // other styles here } styles.scss @import “partial”; @if $someval == true … Read more

Dynamic mixin in Scala – is it possible?

I believe this is impossible to do strictly at runtime, because traits are mixed in at compile-time into new Java classes. If you mix a trait with an existing class anonymously you can see, looking at the classfiles and using javap, that an anonymous, name-mangled class is created by scalac: class Foo { def bar … Read more

What are Mixins (as a concept)

Before going into what a mix-in is, it’s useful to describe the problems it’s trying to solve. Say you have a bunch of ideas or concepts you are trying to model. They may be related in some way but they are orthogonal for the most part — meaning they can stand by themselves independently of … Read more