CSS for Software Engineers for CSS Developers He Harry Roberts - - PowerPoint PPT Presentation

css for software engineers for css developers
SMART_READER_LITE
LIVE PREVIEW

CSS for Software Engineers for CSS Developers He Harry Roberts - - PowerPoint PPT Presentation

CSS for Software Engineers for CSS Developers He Harry Roberts http://csswizardry.com 1959 2015 Flow Matic CSS 1996 5 Principles of Software Engineering 1 DRY Dont repeat yourself Every piece of knowledge must have a single,


slide-1
SLIDE 1

CSS for Software Engineers for CSS Developers

slide-2
SLIDE 2

He

Harry Roberts

http://csswizardry.com

slide-3
SLIDE 3

1959 2015 1996 CSS Flow Matic

slide-4
SLIDE 4

Principles of Software Engineering

5

slide-5
SLIDE 5

DRY Don’t repeat yourself

1

slide-6
SLIDE 6

“Every piece of knowledge must have a single, unambiguous, authoritative representation within a system“

#1

  • wikipedia.org/wiki/Don't_repeat_yourself
slide-7
SLIDE 7

“DRY is not about no repeating anything but is about no

repeating yourself “

  • H. Roberts

#1

slide-8
SLIDE 8

“If you manually type a declaration 50 times in a project, you are repeating yourself: this is not DRY. If you can generate that declaration 50 times without having to manually repeat it, this is DRY: you are generating repetition without actually repeating yourself. This is quite a subtle but important distinction to be aware of”

csswz.it/1ytQkxp

#1

slide-9
SLIDE 9

.u-margin-top { margin-top: 12px; } .u-margin-right { margin-right: 12px; } .u-margin-bottom { margin-bottom: 12px; } .u-margin-left { margin-left: 12px; }

#1

slide-10
SLIDE 10

$unit : 12px .u-margin-top { margin-top: $unit; } .u-margin-right { margin-right: $unit; } .u-margin-bottom { margin-bottom: $unit; } .u-margin-left { margin-left: $unit; }

#1

slide-11
SLIDE 11

.page-title { font-family: “Custom Font”, sans-serif; font-weight: 700; } .btn { font-family: “Custom Font”, sans-serif; font-weight: 700; } .pagination { font-family: “Custom Font”, sans-serif; font-weight: 700; }

#1

slide-12
SLIDE 12

@mixin custom-font() { font-family: “Custom Font”, sans-serif; font-weight: 700; }

.page-title { @include custom-font(); } .btn { @include custom-font(); } .pagination { @include custom-font(); }

#1 Gives the exact same

  • utput, but at least we

haven’t duplicated anything manually

slide-13
SLIDE 13

.btn { color : white; font-weight : bold; } .calendar__title { font-size : 14px; font-weight : bold; } .message { font-weight : bold; }

#1

This is purely coincidental. Don’t try to DRY it out.

slide-14
SLIDE 14

“Repetition is better than wrong abstraction“

#1

  • H. Roberts
slide-15
SLIDE 15
  • Every discrete piece of information should exist only
  • nce.
  • You shouldn’t need to make the same change several

times.

  • Repetition is extra overhead : more to maintain, to go

wrong.

#1

slide-16
SLIDE 16

The single Responsibility Principle

2

slide-17
SLIDE 17

“[...] 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.”

#2

  • wikipedia.org/wiki/Single_responsibility_principle
slide-18
SLIDE 18

Everything should do one job, one job only and should do that job very very well.

#2

slide-19
SLIDE 19

#2

slide-20
SLIDE 20

#sandwich { bread: white; meat: chicken; salad: lettuce, onion, tomato; sauce: mayonnaise; } <div id=”sandwich”> … </div>

#2

slide-21
SLIDE 21

#2 .bread, .bread--white {} .chicken {} .lettuce {} .onion {} .tomato {}

<div class="bread bread--white chicken lettuce onion tomato mayonnaise">...</div>

slide-22
SLIDE 22

.btn-login { display: inline-block; padding: 2em; background-color: green; color: white; }

#2

Structural Responsability Cosmetic Responsability <button class=”btn-login”> … </button>

slide-23
SLIDE 23

.btn { display: inline-block; } .btn--large { padding: 2em; } .btn--positive { background-color: green; color: white; } #2

<button class=”btn btn--large btn-positive”> … </button>

slide-24
SLIDE 24

Provide developers with the ingredients. Let them make the meals.

#2

slide-25
SLIDE 25

The separation

  • f Concerns

3

slide-26
SLIDE 26

“[...] It is, that one is willing to study in depth an aspect

  • f one’s subject matter in isolation for the sake of its
  • wn consistency [...] But nothing is gained—on the

contrary! —by tackling these various aspects

  • simultaneously. It is what I sometimes have called ‘the

separation of concerns’ [...] it does not mean ignoring the other aspects, it is just doing justice to the fact that from this aspect’s point of view, the other is irrelevant. It is being one- and multiple-track minded simultaneously.

#3

  • wikipedia.org/wiki/Separation_of_concerns
slide-27
SLIDE 27

Each thing responsible for itself and nothing more

slide-28
SLIDE 28

Using HTML to provide cosmetics. <font color="red">

#3

<div style=”color : red; “>...</div>

slide-29
SLIDE 29

<nav role="navigation"> <ul> <li> <a>...</a></li> <li><a>...</a> </li> </ul> </nav> [role="navigation"] { ... } [role="navigation"] > ul { ... } [role="navigation"] > ul > li { ... }

#3

slide-30
SLIDE 30

<nav class="site-nav js-site-nav" role="navigation"> <ul class="site-nav__list"> <li class="site-nav__item"> <a class="site-nav__link">...</a> </li> …. </ul> </nav>

#3

slide-31
SLIDE 31

<nav class="site-nav js-site-nav" role="navigation"> <ul class="site-nav__list"> <li class="site-nav__item"> <a class="site-nav__link">...</a> </li> …. </ul> </nav>

#3

Semantic Concern

slide-32
SLIDE 32

#3

Accessibility Concern <nav class="site-nav js-site-nav" role="navigation"> <ul class="site-nav__list"> <li class="site-nav__item"> <a class="site-nav__link">...</a> </li> …. </ul> </nav>

slide-33
SLIDE 33

#3

<nav class="site-nav js-site-nav" role="navigation"> <ul class="site-nav__list"> <li class="site-nav__item"> <a class="site-nav__link">...</a> </li> …. </ul> </nav> Behaviors Concern

slide-34
SLIDE 34

#3

Stylistic Concern <nav class="site-nav js-site-nav" role="navigation"> <ul class="site-nav__list"> <li class="site-nav__item"> <a class="site-nav__link">...</a> </li> …. </ul> </nav>

.site-nav {… .site-nav__list { … .site-nav__link { … } } }

slide-35
SLIDE 35

Only bind CSS onto CSS-based classes only. Don’t write DOM-like selectors. Don’t bind CSS onto data-* attributes. Don’t bind JS onto CSS classes.

#3

slide-36
SLIDE 36

Immutability

4

slide-37
SLIDE 37

“...an immutable object is an object whose state cannot be modified after it is created.

#4

  • wikipedia.org/wiki/Immutable_object
slide-38
SLIDE 38

.col-6 { width: 50%; } @media screen and (max-width: 480px) { .col-6@sm { float: none; width: 100%; } } @media screen and (max-width: 480px) { .col-6 { float: none; width: 100%; } }

#4

slide-39
SLIDE 39

.btn { font-size: 1em; } .promo .btn { font-size: 1.2em; }

#4

slide-40
SLIDE 40

.btn { font-size: 1em; } .btn--large { font-size: 1.2em; }

#4

slide-41
SLIDE 41

Don’t have several states of the same thing. Use Modifiers or Responsive Suffixes

#4

slide-42
SLIDE 42

The Open/Close Principle

5

slide-43
SLIDE 43

“Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.”

#5

  • wikipedia.org/wiki/Open/closed_principle
slide-44
SLIDE 44

“[…] once completed, the implementation of a class could

  • nly be modified to correct errors; new or changed features

would require that a different class be created. That class could reuse coding from the original class through inheritance.

#5

slide-45
SLIDE 45

.btn { … padding: 1em 2em; } .btn--large { … padding: 1.5em 2.5em; }

#5

slide-46
SLIDE 46

Safe way to make changes. Safe way of working with legacy.

slide-47
SLIDE 47
  • 1. DRY - Don’t repeat yourself
  • 2. Single responsibility principle
  • 3. Separation of Concerns
  • 4. Immutability
  • 5. Open/Close principle
slide-48
SLIDE 48

The Moustache Principle

#

slide-49
SLIDE 49

“Just because you can, it doesn’t mean that you should”

#6

  • H. Roberts
slide-50
SLIDE 50

Thank you!!

@aldopizagalli

do-not-reply@frontedersTicino.com

Talk inspired by Henry Roberts slides: https://speakerdeck.com/csswizardry/css-for-software-engineers-for-css-developers video: https://vimeo.com/140641366