Slide 1

Slide 1 text

CSS COMPUTER STYLE SCIENCE fernahh.com.br . { }

Slide 2

Slide 2 text

@fernahh fernahh.com.br

Slide 3

Slide 3 text

ContaAzul contaazul.com

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

why?

Slide 6

Slide 6 text

Antes de tudo, essa não é mais uma palestra sobre SMACSS, BEM ou DRYCSS.

Slide 7

Slide 7 text

Motivação O CSS e seu ecossistema sempre foram distantes da computação.

Slide 8

Slide 8 text

linguagem

Slide 9

Slide 9 text

linguagem comunidade

Slide 10

Slide 10 text

linguagem comunidade design

Slide 11

Slide 11 text

a linguagem.

Slide 12

Slide 12 text

1959 FLOW-MATIC Primeira linguagem de programação semelhante ao idioma inglês (build for humans).

Slide 13

Slide 13 text

Grace Murray Hopper

Slide 14

Slide 14 text

Grace Murray Hopper - Criou o primeiro compilador

Slide 15

Slide 15 text

Grace Murray Hopper - Criou o primeiro compilador - Desenvolveu a Flow-Matic

Slide 16

Slide 16 text

Grace Murray Hopper - Criou o primeiro compilador - Desenvolveu a Flow-Matic - Criou o termo “bug”

Slide 17

Slide 17 text

1959 C Linguagem imperativa e procedural. Foi criada para o desenvolvimento do Unix. 1972

Slide 18

Slide 18 text

1959 SmallTalk É considerada a primeira linguagem orientada objetos. Foi um marco para sua época. 1972 1980

Slide 19

Slide 19 text

1959 ...CSS 1972 1980 1996

Slide 20

Slide 20 text

1959 ...CSS 1972 1980 1996 ~ 4 décadas!

Slide 21

Slide 21 text

“Designing simple style sheets is easy. One needs only to know a little HTML and some basic desktop publishing terminology. E.g., to set the text color of 'H1' elements to blue, one can say: H1 { color: blue }; The example is a simple CSS rule”

Slide 22

Slide 22 text

“Designing simple style sheets is easy. One needs only to know a little HTML and some basic desktop publishing terminology. E.g., to set the text color of 'H1' elements to blue, one can say: H1 { color: blue }; The example is a simple CSS rule”

Slide 23

Slide 23 text

A simplicidade do CSS foi decisiva para o seu sucesso.

Slide 24

Slide 24 text

a comunidade.

Slide 25

Slide 25 text

Designers Em 2013, representavam ~16,8% dos profissionais que trabalhavam com web no Brasil.

Slide 26

Slide 26 text

Comunidade jovem ~76% dos profissionais tem menos de 30 anos, sendo que quase metade tem menos de 25 anos!

Slide 27

Slide 27 text

Experiência back-end Apenas ~23% tem back-end como atuação principal juntamente com front-end. http://tableless.com.br/resultados-do-survey-2015/

Slide 28

Slide 28 text

Fragmentação Além de já ser uma comunidade bastante específica, estamos nos dividindo entre “ui developers” e “javascript developers”.

Slide 29

Slide 29 text

o design.

Slide 30

Slide 30 text

O piloto. Graças a evolução do design que o CSS evoluiu. As features do CSS3 vieram de demandas do design.

Slide 31

Slide 31 text

linguagem comunidade design

Slide 32

Slide 32 text

linguagem comunidade design javascript

Slide 33

Slide 33 text

HTML

Slide 34

Slide 34 text

HTML CSS

Slide 35

Slide 35 text

HTML CSS JavaScript

Slide 36

Slide 36 text

JavaScript CSS HTML

Slide 37

Slide 37 text

O JavaScript se tornou o principal pilar da web. Além de comportamento, ele entrega conteúdo e (algumas vezes) é responsável pelo estilo de uma página web.

Slide 38

Slide 38 text

O mercado mudou. A web agora é uma ótima plataforma para aplicações complexas.

Slide 39

Slide 39 text

Documentos Grupo de páginas que seguem o mesmo padrão de comportamento e estilo.

Slide 40

Slide 40 text

/home

Slide 41

Slide 41 text

/home /products

Slide 42

Slide 42 text

/home /products /product/1

Slide 43

Slide 43 text

Aplicações Ao invés de várias páginas, geralmente é apenas uma com estados diferentes.

Slide 44

Slide 44 text

/signup

Slide 45

Slide 45 text

/signup /step/1

Slide 46

Slide 46 text

/signup /step/1 /step/2

Slide 47

Slide 47 text

A ciência. Aprender boas práticas e paradigmas nos ajudam a evitar cenários caóticos.

Slide 48

Slide 48 text

paradigmas != metodologias (BEM, SMACSS, DRYCSS, …)

Slide 49

Slide 49 text

Apesar de ser uma linguagem declarativa, CSS também pode atender a outros paradigmas computacionais.

Slide 50

Slide 50 text

Paradigma Imperativo Baseado em uma sequência de comandos que determinam como o computador vai executar uma tarefa.

Slide 51

Slide 51 text

Uma das principais características do paradigma imperativo é a sua relação com linguagens procedurais.

Slide 52

Slide 52 text

html { font-family: sans-serif; line-height: 1.15; } body { margin: 0; } article, aside, footer, header, section { display: block; } h1 { font-size: 2em; margin: 0.67em 0; }

Slide 53

Slide 53 text

html { font-family: sans-serif; line-height: 1.15; } body { margin: 0; } article, aside, footer, header, section { display: block; } h1 { font-size: 2em; margin: 0.67em 0; }

Slide 54

Slide 54 text

html { font-family: sans-serif; line-height: 1.15; } body { margin: 0; } article, aside, footer, header, section { display: block; } h1 { font-size: 2em; margin: 0.67em 0; } normalize.css 461 linhas. (com comentários)

Slide 55

Slide 55 text

/* ========================== Section comment block ========================== */ /* Sub-section comment block ========================== */ /** * Short description using * Doxygen-style comment format * * The first sentence of the long * description starts here and * continues on this * line for a while finally concluding * here at the end of this paragraph. * */ /* Basic comment */ idiomatic-css https://github.com/necolas/idiomatic-css

Slide 56

Slide 56 text

Outra característica forte do paradigma imperativo é permitir que o desenvolvedor controle o fluxo de execução.

Slide 57

Slide 57 text

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

Slide 58

Slide 58 text

body { color: green; } Lorem ipsum dolor sit amet, consectetur adipisicing elit.

Slide 59

Slide 59 text

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Brand

Slide 60

Slide 60 text

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Brand header { color: white !important; }

Slide 61

Slide 61 text

Caos! CSS sempre foi conhecido por ser difícil de escalar e dar manutenção.

Slide 62

Slide 62 text

Além do caos e todos, vieram piadas que já perderam graça há mais de 5 anos…

Slide 63

Slide 63 text

Além do caos e todos, vieram piadas que já perderam graça há mais de 5 anos…

Slide 64

Slide 64 text

DRY Cada parte de um sistema deve ter uma representação única e livre de ambiguidades.

Slide 65

Slide 65 text

representação única.

Slide 66

Slide 66 text

.Header { background: #ffffff; } .Article { background: #ffffff; } .Footer { background: #ffffff; }

Slide 67

Slide 67 text

.Header { background: #ffffff; } .Article { background: #ffffff; } .Footer { background: #ffffff; }

Slide 68

Slide 68 text

.Header { background: #ffffff; } .Article { background: #ffffff; } .Footer { background: #ffffff; } .Header, .Article, .Footer { background: #ffffff; }

Slide 69

Slide 69 text

livre de ambiguidades.

Slide 70

Slide 70 text

.b { } botão?

Slide 71

Slide 71 text

botão? bold? .b { }

Slide 72

Slide 72 text

botão? bold? “uma bola” .b { }

Slide 73

Slide 73 text

Metodologias de escrita como SMACSS e BEM buscam resolver problemas com seletores ambíguos.

Slide 74

Slide 74 text

.Button { /*...*/ } .Button__Anchor_icon { /*...*/ } .Button--danger { /*...*/ } BEM Block. Element. Modifier.

Slide 75

Slide 75 text

.Button { /*...*/ } .Button__Anchor_icon { /*...*/ } .Button--danger { /*...*/ } BEM Block. Element. Modifier. bloco

Slide 76

Slide 76 text

.Button { /*...*/ } .Button__Anchor_icon { /*...*/ } .Button--danger { /*...*/ } BEM Block. Element. Modifier. elemento

Slide 77

Slide 77 text

.Button { /*...*/ } .Button__Anchor_icon { /*...*/ } .Button--danger { /*...*/ } BEM Block. Element. Modifier. modificador

Slide 78

Slide 78 text

.comment-box { /*...*/ } .comment-box.is-open { /*...*/ } .button-black { /*...*/ } SMACSS Scalable and Modular Architecture for CSS.

Slide 79

Slide 79 text

.comment-box { /*...*/ } .comment-box.is-open { /*...*/ } .button-black { /*...*/ } SMACSS Scalable and Modular Architecture for CSS. módulo

Slide 80

Slide 80 text

.comment-box { /*...*/ } .comment-box.is-open { /*...*/ } .button-black { /*...*/ } SMACSS Scalable and Modular Architecture for CSS. estado

Slide 81

Slide 81 text

.comment-box { /*...*/ } .comment-box.is-open { /*...*/ } .button-black { /*...*/ } SMACSS Scalable and Modular Architecture for CSS. tema

Slide 82

Slide 82 text

Metodologias tiveram um papel importante na evolução de como escrevemos CSS, mas elas são facilmente violáveis.

Slide 83

Slide 83 text

A era dos pré-processadores. Less, Sass e Stylus foram decisivos para a evolução da web e do CSS.

Slide 84

Slide 84 text

Variáveis. Exemplo no SCSS. $bgColor: #ffffff; .Header { background: $bgColor; } .Article { background: $bgColor; } .Footer { background: $bgColor; }

Slide 85

Slide 85 text

:root { --bgColor: #ffffff; } .Header { background: var(--bgColor); } .Article { background: var(--bgColor); } .Footer { background: var(--bgColor); } Custom Properties. “Variáveis” nativas do CSS.

Slide 86

Slide 86 text

.Notification--warning { font-size: 2em; font-weight: bold; } .Notification--danger { font-size: 2em; font-weight: bold; } .Notification--success { font-size: 2em; font-weight: bold; }

Slide 87

Slide 87 text

.Notification--warning { font-size: 2em; font-weight: bold; } .Notification--danger { font-size: 2em; font-weight: bold; } .Notification--success { font-size: 2em; font-weight: bold; }

Slide 88

Slide 88 text

@mixin notification { font-size: 2em; font-weight: bold; }; .Notification--warning { @extend notification(); } .Article { @extend notification(); } .Footer { @extend notification(); } Mixins. Exemplo no SCSS.

Slide 89

Slide 89 text

:root { --notification: { font-size: 2em; font-weight: bold; }; } .Notification--warning { @apply --notification; } .Article { @apply --notification; } .Footer { @apply --notification; } @apply rule. “Mixin” nativo do CSS.

Slide 90

Slide 90 text

:root { --notification: { font-size: 2em; font-weight: bold; }; } .Notification--warning { @apply --notification; } .Article { @apply --notification; } .Footer { @apply --notification; } @apply rule. “Mixin” nativo do CSS. custom property

Slide 91

Slide 91 text

Apesar de úteis, os pré-processadores possuem um problema que vários softwares tiveram: estrutura monolítica.

Slide 92

Slide 92 text

monolito

Slide 93

Slide 93 text

monolito microserviços

Slide 94

Slide 94 text

Além de problemas de escalabilidade, estruturas monolíticas exigem um grande conhecimento da base de código.

Slide 95

Slide 95 text

A era dos pós-processadores. Pós-processar o CSS nos permite contribuir com a evolução da comunidade.

Slide 96

Slide 96 text

PostCSS

Slide 97

Slide 97 text

PostCSS linter

Slide 98

Slide 98 text

PostCSS linter autoprefixer

Slide 99

Slide 99 text

PostCSS linter autoprefixer transpiler

Slide 100

Slide 100 text

PostCSS linter autoprefixer transpiler .{ }

Slide 101

Slide 101 text

PostCSS linter autoprefixer transpiler .{ }

Slide 102

Slide 102 text

PostCSS linter autoprefixer transpiler .{ }

Slide 103

Slide 103 text

PostCSS é a crista da onda. Possui mais de 200 plugins, é bem aceito pela comunidade e future proof!

Slide 104

Slide 104 text

A era pós CSS3. A evolução das specs CSS estão rápidas e próximas dos approaches.

Slide 105

Slide 105 text

Orientação a Objetos Possui classes que definem objetos de um sistema. Cada uma dessas especifica o comportamento e estados de seus objetos e o relacionamento com outros objetos.

Slide 106

Slide 106 text

OOCSS foi importante para a sua época. Porém, desde 2011 não há mais atualizações em sua especificação.

Slide 107

Slide 107 text

O paradigma de Orientação a Objetos não se limita a implementação sugerida pelo OOCSS.

Slide 108

Slide 108 text

S.O.L.I.D. Cada letra representa um princípio da Orientação a Objetos que nos ajuda a manter um código saudável.

Slide 109

Slide 109 text

Single Responsibility Principle: diz que todas nossas abstrações devem ter uma única responsabilidade.

Slide 110

Slide 110 text

.Button--disabled { display: flex; max-width: 320em; background: red; }

Slide 111

Slide 111 text

.Button--disabled { display: flex; max-width: 320em; background: red; } box-model

Slide 112

Slide 112 text

.Button--disabled { display: flex; max-width: 320em; background: red; } estilo

Slide 113

Slide 113 text

.Button { display: flex; max-width: 320em; } .Button--disabled { display: flex; max-width: 320em; background: red; } box-model

Slide 114

Slide 114 text

.Button { display: flex; max-width: 320em; } .Danger { background: red; } .Button--disabled { display: flex; max-width: 320em; background: red; } estilos

Slide 115

Slide 115 text

Open Closed Principle: quando você tem uma abstração, ao invés de modificá-la, permita que ela possa ser estendida ou usada para compor algo.

Slide 116

Slide 116 text

Se uma abstração não é sua, não modifique-a!

Slide 117

Slide 117 text

Muitos projetos ainda usam Bootstrap v2.x por conta das “personalizações” nos componentes do framework.

Slide 118

Slide 118 text

O @extend do Sass foi um grande vilão de projetos que estendem classes de frameworks CSS.

Slide 119

Slide 119 text

.btn { display: block; /*...*/ } .btn-login { @extend .btn; }

Slide 120

Slide 120 text

.btn { display: block; /*...*/ } .btn-login { @extend .btn; }

Slide 121

Slide 121 text

.btn { display: block; /*...*/ } .btn-login { @extend .btn; } .btn, .btn-login { display: block; /*...*/ }

Slide 122

Slide 122 text

.btn { display: block; /*...*/ } .btn-login { @extend .btn; } .header .btn { background: red; /*...*/ }

Slide 123

Slide 123 text

.btn { display: block; /*...*/ } .btn-login { @extend .btn; }; .header .btn { background: red; /*...*/ };

Slide 124

Slide 124 text

.btn { display: block; /*...*/ }; .btn-login { @extend .btn; } .header .btn { background: red; /*...*/ }

Slide 125

Slide 125 text

.btn { display: block; /*...*/ } .btn-login { @extend .btn; } .header .btn { background: red; /*...*/ } .btn, .btn-login { display: block; /*...*/ } .header .btn, .header .btn-login { background: red; /*...*/ }

Slide 126

Slide 126 text

Dica de ouro: se for usar @extend no Sass, evite usar classes, vá de placeholders.

Slide 127

Slide 127 text

Herança. Usada para reaproveitamento de código. A ideia é simples: objetos compartilharem propriedades.

Slide 128

Slide 128 text

:root { --notification: { font-size: 2em; font-weight: bold; }; } .Notification--warning { @apply --notification; } .Article { @apply --notification; } .Footer { @apply --notification; } herança com @apply rule.

Slide 129

Slide 129 text

É importante utilizar herança para melhorar a expressividade de seu código.

Slide 130

Slide 130 text

.Card::before { content: ''; /*...*/ }

Slide 131

Slide 131 text

.Card::before { content: ''; /*...*/ }

Slide 132

Slide 132 text

:root { --fold: { /*...*/ } } .Card::before { @apply --fold; }

Slide 133

Slide 133 text

:root { --fold: { /*...*/ } } .Card::before { @apply --fold; } Lorem ipsum dolor sit amet, consectetur adipisicing elit.

Slide 134

Slide 134 text

Lembre-se: custom properties funcionam da mesma forma que as outras, ou seja, são manipuladas pelo efeito cascata.

Slide 135

Slide 135 text

Programação Funcional É inspirado em funções matemáticas, ou seja, dado uma entrada você terá sempre a mesma saída. O paradigma funcional busca manter qualquer valor imutável.

Slide 136

Slide 136 text

Composição: Assim como você compõe pequenas funções, você pode compor pequenas classes.

Slide 137

Slide 137 text

“O melhor approach para escrever CSS é escrever o menos CSS possível.”

Slide 138

Slide 138 text

EXCLUIR

Slide 139

Slide 139 text

EXCLUIR

Slide 140

Slide 140 text

EXCLUIR

Slide 141

Slide 141 text

EXCLUIR

Slide 142

Slide 142 text

O caso .size-flex.

Slide 143

Slide 143 text

Precisávamos de uma classe que colocasse 100% de largura em botões. But, não tínhamos botões flexíveis componentizado...

Slide 144

Slide 144 text

No content

Slide 145

Slide 145 text

No content

Slide 146

Slide 146 text

Hoje essa classe é usada em 58 arquivos HTML, e aparece 110 vezes.

Slide 147

Slide 147 text

Classes enxutas são amor, deixei seu preconceito de lado.

Slide 148

Slide 148 text

Imutabilidade: nos dá uma das coisas mais difíceis de se ter em CSS: confiança de que o que você escrever é o que vai ser renderizado.

Slide 149

Slide 149 text

.no-text-transform { text-transform: none !important; } .no-padding-bottom { padding-bottom: 0 !important; } .no-padding-top { padding-top: 0 !important; } Uma das formas de garantirmos a imutabilidade de uma classe é usando !important.

Slide 150

Slide 150 text

immutablecss.com

Slide 151

Slide 151 text

tachyons.io

Slide 152

Slide 152 text

funkcss.com

Slide 153

Slide 153 text

Além de evitar o problema com especificidade, CSS funcional te faz pensar melhor em componentes.

Slide 154

Slide 154 text

CSS Funcional é legal pela simplicidade.

Slide 155

Slide 155 text

Orientação a Objetos faz sentido em ambientes extremamente controlados.

Slide 156

Slide 156 text

Escolha uma abordagem em que você escreva cada vez menos CSS.

Slide 157

Slide 157 text

Mantenha sua stack simples e plugável.

Slide 158

Slide 158 text

Busque sempre estudar paradigmas.

Slide 159

Slide 159 text

Exclua CSS, isso evita que seu código apodreça.

Slide 160

Slide 160 text

O CSS pode ser seu melhor amigo. Faça projetos incríveis.

Slide 161

Slide 161 text

obrigado! @fernahh fernahh.com.br