css for software engineers for css developers
play

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,


  1. CSS for Software Engineers for CSS Developers

  2. He Harry Roberts http://csswizardry.com

  3. 1959 2015 Flow Matic CSS 1996

  4. 5 Principles of Software Engineering

  5. 1 DRY Don’t repeat yourself

  6. “Every piece of knowledge must have a single, unambiguous, authoritative representation within a system“ - wikipedia.org/wiki/Don't_repeat_yourself #1

  7. “ DRY is not about no repeating anything but is about no repeating yourself “ - H. Roberts #1

  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

  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

  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

  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

  12. @mixin custom-font() { font-family: “Custom Font”, sans-serif; font-weight: 700; } .page-title { Gives the exact same @include custom-font(); output, but at least we } haven’t duplicated anything manually .btn { @include custom-font(); } .pagination { @include custom-font(); } #1

  13. .btn { color : white; font-weight : bold; } This is purely coincidental. .calendar__title { Don’t try to font-size : 14px; font-weight : bold; DRY it out. } .message { font-weight : bold; } #1

  14. “Repetition is better than wrong abstraction“ - H. Roberts #1

  15. - Every discrete piece of information should exist only once. - You shouldn’t need to make the same change several times. - Repetition is extra overhead : more to maintain, to go wrong. #1

  16. 2 The single Responsibility Principle

  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.” - wikipedia.org/wiki/Single_responsibility_principle #2

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

  19. #2

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

  21. .bread, .bread--white {} .chicken {} .lettuce {} .onion {} .tomato {} <div class="bread bread--white chicken lettuce onion tomato mayonnaise">...</div> #2

  22. .btn-login { display: inline-block; Structural padding: 2em; Responsability background-color: green; color: white; } Cosmetic Responsability <button class=”btn-login”> … </button> #2

  23. .btn { display: inline-block; } .btn--large { <button class=”btn btn--large padding: 2em; btn-positive”> … </button> } .btn--positive { background-color: green; color: white; } #2

  24. Provide developers with the ingredients. Let them make the meals. #2

  25. 3 The separation of Concerns

  26. “[...] It is, that one is willing to study in depth an aspect of one’s subject matter in isolation for the sake of its own 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. wikipedia.org/wiki/Separation_of_concerns #3

  27. Each thing responsible for itself and nothing more

  28. Using HTML to provide cosmetics. <font color="red"> <div style=”color : red; “>...</div> #3

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

  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

  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> Semantic Concern #3

  32. <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> Accessibility Concern #3

  33. <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 #3

  34. <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> .site-nav {… …. .site-nav__list { … </ul> .site-nav__link { … } </nav> } Stylistic } Concern #3

  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

  36. 4 Immutability

  37. “...an immutable object is an object whose state cannot be modified after it is created. - wikipedia.org/wiki/Immutable_object #4

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

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

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

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

  42. 5 The Open/Close Principle

  43. “Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.” - wikipedia.org/wiki/Open/closed_principle #5

  44. “[…] once completed, the implementation of a class could only 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

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

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

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

  48. # The Moustache Principle

  49. “Just because you can, it doesn’t mean that you should” H. Roberts #6

  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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend