06-02-2019 - Bram Smulders
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
[...] the practice of structuring information models and associated schemata such that every data element is stored exactly once.
[...] the single responsibility principle states that every class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class.
We should be able to understand individual parts of a program in complete isolation. We should be able to study one aspect of a program without worrying about any other unrelated part.- Harry Roberts
.margin-top { margin-top: 24px; }
.margin-right { margin-right: 24px; }
.margin-bottom { margin-bottom: 24px; }
.margin-left { margin-left: 24px; }
$space: 24px;
.margin-top { margin-top: $space; }
.margin-right { margin-right: $space; }
.margin-bottom { margin-bottom: $space; }
.margin-left { margin-left: $space; }
Much better!
The subway analogy
.sandwich {
bread: white;
meat: chicken;
salad: lettuce, onion, tomato;
sauce: mayonnaise;
}
...
The subway analogy
.bread,
.bread--white {}
.chicken {}
.lettuce {}
.onion {}
.tomato {}
.mayonnaise {}
...
The subway analogy
.bread,
.bread--white {}
.chicken {}
.lettuce {}
.onion {}
.tomato {}
.mayonnaise {}
...
.button-login {
display: inline-block;
padding: 2em;
background-color: green;
color: white;
}
Mixing responsibilities: base, structure, cosmetic
.button {
display: inline-block;
padding: 1em;
}
.button--large {
padding: 2em;
}
.button--positive {
background-color: green;
color: white;
}
Everything has one reason to change. Much better!
.button {}
.button--large {}
.button--small {}
.button--positive {}
.button--negative {}
.button--full {}
Mix and match classes to make lots of variaties of our button.
— Every developer ever
.media
..user-avatar-link
).
.list-clean {}
Generic list, could contain any kind of content.
Reusable icon class .icon
.
.media {}
.media__fit {}
.media__fill {}
Reusable media object.
-
Sweet!
A sane, scalable, managed architecture for CSS.
Bram Smulders
bramsmulders.com
@bramsmulders
bramsmulders.github.io/slides