SlideShare ist ein Scribd-Unternehmen logo
1 von 73
Downloaden Sie, um offline zu lesen
Problemas que o Elm resolve
só com o compilador
sem nada mais
@cuducos
cuducos.me
1 / 73
2 / 73
3 / 73
4 / 73
5 / 73
6 / 73
“O melhor caso de uso de Haskell”
— Felipe de Morais
7 / 73
$ elm-make Main.elm  --warn
8 / 73
Propriedades que podem não existir
1
9 / 73
user = {
name: 'Eduardo Cuducos',
twitter: 'cuducos'
}
const getSocialMedia = (user) => user.facebook
getSocialMedia(user)
10 / 73
user = {
name: 'Eduardo Cuducos',
twitter: 'cuducos'
}
const getSocialMedia = (user) => user.facebook
getSocialMedia(user)
undefined
11 / 73
class User:
def __init__(self, name, twitter):
self.name = name
self.twitter = twitter
user = User('Eduardo Cuducos', 'cuducos')
def get_social_media(user):
return user.facebook
get_social_media(user)
12 / 73
class User:
def __init__(self, name, twitter):
self.name = name
self.twitter = twitter
user = User('Eduardo Cuducos', 'cuducos')
def get_social_media(user):
return user.facebook
get_social_media(user)
AttributeError: 'User' object has no attribute 'facebook'
13 / 73
type alias User =
{ name : String
, twitter : String
}
getSocialMedia : User -> String
getSocialMedia user =
user.facebook
14 / 73
type alias User =
{ name : String
, twitter : String
}
getSocialMedia : User -> String
getSocialMedia user =
user.facebook
-- TYPE MISMATCH ------------------------------------------------------ Main.elm
`user` does not have a field named `facebook`.
15| user.facebook
^^^^^^^^^^^^^
The type of `user` is:
User
Which does not contain a field named `facebook`.
Hint: The record fields do not match up. One has name and twitter. The other has
facebook.
15 / 73
type alias User =
{ name : String
, twitter : String
}
getSocialMedia : User -> String
getSocialMedia user =
user.twitter
16 / 73
type alias User =
{ name : String
, twitter : String
}
getSocialMedia : User -> String
getSocialMedia user =
user.twitter
Success! Compiled 1 module.
17 / 73
Elm não te deixa com
o undefined na mão!
18 / 73
Objetos que podem não existir
2
19 / 73
users = [
{ name: 'Eduardo Cuducos', twitter: 'cuducos' },
{ name: 'Hugo Bessa', twitter: 'hugobessaa' }
]
const firstUserName = (users) => users[0].name
firstUserName(users)
20 / 73
users = [
{ name: 'Eduardo Cuducos', twitter: 'cuducos' },
{ name: 'Hugo Bessa', twitter: 'hugobessaa' }
]
const firstUserName = (users) => users[0].name
firstUserName(users)
'Eduardo Cuducos'
21 / 73
users = []
firstUserName(users)
22 / 73
users = []
firstUserName(users)
TypeError: Cannot read property 'name' of undefined
23 / 73
users = [
User('Eduardo Cuducos', 'cuducos'),
User('Hugo Bessa', 'hugobessaa')
]
def first_user_name(users):
return users[0].name
first_user_name(users)
24 / 73
users = [
User('Eduardo Cuducos', 'cuducos'),
User('Hugo Bessa', 'hugobessaa')
]
def first_user_name(users):
return users[0].name
first_user_name(users)
'Eduardo Cuducos'
25 / 73
users = []
first_user_name(users)
26 / 73
users = []
first_user_name(users)
IndexError: list index out of range
27 / 73
users = []
first_user_name(users)
IndexError: list index out of range
def first_user_name(users):
first_user, *_ = users
return first_use.name
28 / 73
users = []
first_user_name(users)
IndexError: list index out of range
def first_user_name(users):
first_user, *_ = users
return first_use.name
ValueError: not enough values to unpack (expected at least 1, got 0)
29 / 73
firstUserName : List User -> String
firstUserName users =
let
firstUser = List.head users
in
firstUser.name
30 / 73
firstUserName : List User -> String
firstUserName users =
let
firstUser = List.head users
in
firstUser.name
-- TYPE MISMATCH --------------------------------------------- Main.elm
`firstUser` does not have a field named `name`.
29| firstUser.name
^^^^^^^^^^^^^^
The type of `firstUser` is:
Maybe User
Which does not contain a field named `name`.
31 / 73
firstUserName : List User -> String
firstUserName users =
case List.head users of
Just user ->
user.name
Nothing ->
"User not found"
32 / 73
firstUserName : List User -> String
firstUserName users =
case List.head users of
Just user ->
user.name
Nothing ->
"User not found"
Success! Compiled 1 module.
33 / 73
Elm te obri a a preparar a
aplicação para casos raros, extremos!
34 / 73
Missão impossível
3
35 / 73
const tomorrow = (today) => parseInt(today) + 1
tomorrow('18')
36 / 73
const tomorrow = (today) => parseInt(today) + 1
tomorrow('18')
19
37 / 73
tomorrow(undefined)
38 / 73
tomorrow(undefined)
NaN
39 / 73
def tomorrow(today):
return int(today) + 1
tomorrow('18')
40 / 73
def tomorrow(today):
return int(today) + 1
tomorrow('18')
19
41 / 73
tomorrow(None)
42 / 73
tomorrow(None)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
43 / 73
tomorrow(None)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
tomorrow('NaN')
44 / 73
tomorrow(None)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
tomorrow('NaN')
ValueError: invalid literal for int() with base 10: 'NaN'
45 / 73
tomorrow : String -> Int
tomorrow today =
(String.toInt today) + 1
46 / 73
tomorrow : String -> Int
tomorrow today =
(String.toInt today) + 1
-- TYPE MISMATCH ------------------------------------------------------ Main.elm
The left argument of (+) is causing a type mismatch.
45| (String.toInt today) + 1
^^^^^^^^^^^^^^^^^^
(+) is expecting the left argument to be a:
number
But the left argument is:
Result String Int
47 / 73
tomorrow : String -> Int
tomorrow today =
case String.toInt today of
Ok day ->
day + 1
Err _ ->
Debug.crash "TODO"
48 / 73
tomorrow : String -> Int
tomorrow today =
case String.toInt today of
Ok day ->
day + 1
Err _ ->
Debug.crash "TODO"
Success! Compiled 1 module.
49 / 73
Elm te obri a a se antecipar a erros
em tempo de execução.
50 / 73
Mas e o Debug.crash?
51 / 73
view : String -> Html msg
view today =
case String.toInt today of
Ok day ->
viewMyApp
Err error ->
viewErroMsg error
52 / 73
Ações de usuário não previstas
4
53 / 73
‑ 41 +
54 / 73
const counter = (state, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1
case 'DECREMENT':
return state - 1
}
}
55 / 73
const counter = (state, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1
case 'DECREMENT':
return state - 1
}
}
const render = () => ReactDOM.render(
<p>
<button onClick={() => store.dispatch({ type: 'DECREMENT'})}>-</button>
{store.getState()}
<button onClick={() => store.dispatch({ type: 'INCREMENT'})}>+</button>
</p>
)
56 / 73
const counter = (state, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1
case 'DECREMENT':
return state - 1
}
}
const render = () => ReactDOM.render(
<p>
<button onClick={() => store.dispatch({ type: 'DECREMENT'})}>-</button>
{store.getState()}
<button onClick={() => store.dispatch({ type: 'INCREMENT'})}>+</button>
</p>
)
+
57 / 73
const counter = (state, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1
case 'DECREMENT':
return state - 1
}
}
const render = () => ReactDOM.render(
<p>
<button onClick={() => store.dispatch({ type: 'DECREMENT'})}>-</button>
{store.getState()}
<button onClick={() => store.dispatch({ type: 'INCREMENT'})}>+</button>
</p>
)
+
42
58 / 73
‑ 21 + x2
59 / 73
const render = () => ReactDOM.render(
<p>
<button onClick={() => store.dispatch({ type: 'DECREMENT'})}>-</button>
{store.getSate()}
<button onClick={() => store.dispatch({ type: 'INCREMENT'})}>+</button>
<button onClick={() => store.dispatch({ type: 'DOUBLE'})}>x2</button>
</p>
)
60 / 73
const render = () => ReactDOM.render(
<p>
<button onClick={() => store.dispatch({ type: 'DECREMENT'})}>-</button>
{store.getSate()}
<button onClick={() => store.dispatch({ type: 'INCREMENT'})}>+</button>
<button onClick={() => store.dispatch({ type: 'DOUBLE'})}>x2</button>
</p>
)
x2
61 / 73
const render = () => ReactDOM.render(
<p>
<button onClick={() => store.dispatch({ type: 'DECREMENT'})}>-</button>
{store.getSate()}
<button onClick={() => store.dispatch({ type: 'INCREMENT'})}>+</button>
<button onClick={() => store.dispatch({ type: 'DOUBLE'})}>x2</button>
</p>
)
x2
21
62 / 73
type Msg = Increment | Decrement
update : Msg -> Int -> Int
update msg model =
case msg of
Increment -> model + 1
Decrement -> model - 1
view : Int -> Html Msg
view model =
p
[]
[ button [ onClick Increment ] [ text "+" ]
, text (toString model)
, button [ onClick Decrement ] [ text "-" ]
]
63 / 73
type Msg = Increment | Decrement
update : Msg -> Int -> Int
update msg model =
case msg of
Increment -> model + 1
Decrement -> model - 1
view : Int -> Html Msg
view model =
p
[]
[ button [ onClick Increment ] [ text "+" ]
, text (toString model)
, button [ onClick Decrement ] [ text "-" ]
]
‑ 21 +
64 / 73
view : Int -> Html Msg
view model =
p
[]
[ button [ onClick Increment ] [ text "+" ]
, text (toString model)
, button [ onClick Decrement ] [ text "-" ]
, button [ onClick Double ] [ text "2x" ]
]
65 / 73
view : Int -> Html Msg
view model =
p
[]
[ button [ onClick Increment ] [ text "+" ]
, text (toString model)
, button [ onClick Decrement ] [ text "-" ]
, button [ onClick Double ] [ text "2x" ]
]
-- NAMING ERROR ------------------------------------------------------- Main.elm
Cannot find variable `Double`
82| , button [ onClick Double ] [ text "2x" ]
66 / 73
type Msg = Increment | Decrement | Double
67 / 73
type Msg = Increment | Decrement | Double
-- MISSING PATTERNS --------------------------------------------------- Main.elm
This `case` does not have branches for all possibilities.
68|> case msg of
69|> Increment ->
70|> model + 1
71|>
72|> Decrement ->
73|> model - 1
You need to account for the following values:
Main.Double
Add a branch to cover this pattern!
68 / 73
update : Msg -> Int -> Int
update msg model =
case msg of
Increment -> model + 1
Decrement -> model - 1
Double -> model * 2
69 / 73
update : Msg -> Int -> Int
update msg model =
case msg of
Increment -> model + 1
Decrement -> model - 1
Double -> model * 2
Success! Compiled 1 module.
70 / 73
A arquitetura do Elm te dá arantia de que todas
as ações dos usuários estão previstas!
71 / 73
“Quem aprendeu al o novo hoje?”
— Raymond Hettin er
72 / 73
Muito obri ado : )
@cuducos
cuducos.me/blo
Vamos aprender Elm!
73 / 73

Weitere ähnliche Inhalte

Was ist angesagt?

Python data structures
Python data structuresPython data structures
Python data structures
Harry Potter
 

Was ist angesagt? (15)

Drupal csu-open atriumname
Drupal csu-open atriumnameDrupal csu-open atriumname
Drupal csu-open atriumname
 
Groovy puzzlers jug-moscow-part 2
Groovy puzzlers jug-moscow-part 2Groovy puzzlers jug-moscow-part 2
Groovy puzzlers jug-moscow-part 2
 
RxSwift 시작하기
RxSwift 시작하기RxSwift 시작하기
RxSwift 시작하기
 
Intro to programming games with clojure
Intro to programming games with clojureIntro to programming games with clojure
Intro to programming games with clojure
 
Python data structures
Python data structuresPython data structures
Python data structures
 
Library management
Library managementLibrary management
Library management
 
From java to kotlin beyond alt+shift+cmd+k - Droidcon italy
From java to kotlin beyond alt+shift+cmd+k - Droidcon italyFrom java to kotlin beyond alt+shift+cmd+k - Droidcon italy
From java to kotlin beyond alt+shift+cmd+k - Droidcon italy
 
[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2
 
Data types
Data typesData types
Data types
 
Lenses
LensesLenses
Lenses
 
Upload text JAVA SCRIPT
Upload text JAVA SCRIPTUpload text JAVA SCRIPT
Upload text JAVA SCRIPT
 
Python avanzado - parte 1
Python avanzado - parte 1Python avanzado - parte 1
Python avanzado - parte 1
 
Rspec and Rails
Rspec and RailsRspec and Rails
Rspec and Rails
 
The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212
 
Creating masterpieces with raphael
Creating masterpieces with raphaelCreating masterpieces with raphael
Creating masterpieces with raphael
 

Ähnlich wie TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had a SRE team at - Problemas que o Elm resolve só com o compilador sem nada mais.

Polygon.javapublic class Polygon { private int numSides; priva.pdf
Polygon.javapublic class Polygon { private int numSides; priva.pdfPolygon.javapublic class Polygon { private int numSides; priva.pdf
Polygon.javapublic class Polygon { private int numSides; priva.pdf
apnafreez
 
Polygon.javapublic class Polygon { private int numSides; priva.pdf
Polygon.javapublic class Polygon { private int numSides; priva.pdfPolygon.javapublic class Polygon { private int numSides; priva.pdf
Polygon.javapublic class Polygon { private int numSides; priva.pdf
apnafreez
 
JavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your codeJavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your code
Laurence Svekis ✔
 

Ähnlich wie TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had a SRE team at - Problemas que o Elm resolve só com o compilador sem nada mais. (20)

RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”
 
PureScript & Pux
PureScript & PuxPureScript & Pux
PureScript & Pux
 
Where's My SQL? Designing Databases with ActiveRecord Migrations
Where's My SQL? Designing Databases with ActiveRecord MigrationsWhere's My SQL? Designing Databases with ActiveRecord Migrations
Where's My SQL? Designing Databases with ActiveRecord Migrations
 
The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみた
 
Django - sql alchemy - jquery
Django - sql alchemy - jqueryDjango - sql alchemy - jquery
Django - sql alchemy - jquery
 
Polygon.javapublic class Polygon { private int numSides; priva.pdf
Polygon.javapublic class Polygon { private int numSides; priva.pdfPolygon.javapublic class Polygon { private int numSides; priva.pdf
Polygon.javapublic class Polygon { private int numSides; priva.pdf
 
Polygon.javapublic class Polygon { private int numSides; priva.pdf
Polygon.javapublic class Polygon { private int numSides; priva.pdfPolygon.javapublic class Polygon { private int numSides; priva.pdf
Polygon.javapublic class Polygon { private int numSides; priva.pdf
 
Redux for ReactJS Programmers
Redux for ReactJS ProgrammersRedux for ReactJS Programmers
Redux for ReactJS Programmers
 
JavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your codeJavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your code
 
Idioms in swift 2016 05c
Idioms in swift 2016 05cIdioms in swift 2016 05c
Idioms in swift 2016 05c
 
Cc code cards
Cc code cardsCc code cards
Cc code cards
 
JavaScript Refactoring
JavaScript RefactoringJavaScript Refactoring
JavaScript Refactoring
 
C++ L09-Classes Part2
C++ L09-Classes Part2C++ L09-Classes Part2
C++ L09-Classes Part2
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
JavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScriptJavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScript
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
Structures
StructuresStructures
Structures
 

Mehr von tdc-globalcode

Mehr von tdc-globalcode (20)

TDC2019 Intel Software Day - Visao Computacional e IA a servico da humanidade
TDC2019 Intel Software Day - Visao Computacional e IA a servico da humanidadeTDC2019 Intel Software Day - Visao Computacional e IA a servico da humanidade
TDC2019 Intel Software Day - Visao Computacional e IA a servico da humanidade
 
TDC2019 Intel Software Day - Tecnicas de Programacao Paralela em Machine Lear...
TDC2019 Intel Software Day - Tecnicas de Programacao Paralela em Machine Lear...TDC2019 Intel Software Day - Tecnicas de Programacao Paralela em Machine Lear...
TDC2019 Intel Software Day - Tecnicas de Programacao Paralela em Machine Lear...
 
TDC2019 Intel Software Day - ACATE - Cases de Sucesso
TDC2019 Intel Software Day - ACATE - Cases de SucessoTDC2019 Intel Software Day - ACATE - Cases de Sucesso
TDC2019 Intel Software Day - ACATE - Cases de Sucesso
 
TDC2019 Intel Software Day - Otimizacao grafica com o Intel GPA
TDC2019 Intel Software Day - Otimizacao grafica com o Intel GPATDC2019 Intel Software Day - Otimizacao grafica com o Intel GPA
TDC2019 Intel Software Day - Otimizacao grafica com o Intel GPA
 
TDC2019 Intel Software Day - Deteccao de objetos em tempo real com OpenVino
TDC2019 Intel Software Day - Deteccao de objetos em tempo real com OpenVinoTDC2019 Intel Software Day - Deteccao de objetos em tempo real com OpenVino
TDC2019 Intel Software Day - Deteccao de objetos em tempo real com OpenVino
 
TDC2019 Intel Software Day - OpenCV: Inteligencia artificial e Visao Computac...
TDC2019 Intel Software Day - OpenCV: Inteligencia artificial e Visao Computac...TDC2019 Intel Software Day - OpenCV: Inteligencia artificial e Visao Computac...
TDC2019 Intel Software Day - OpenCV: Inteligencia artificial e Visao Computac...
 
TDC2019 Intel Software Day - Inferencia de IA em edge devices
TDC2019 Intel Software Day - Inferencia de IA em edge devicesTDC2019 Intel Software Day - Inferencia de IA em edge devices
TDC2019 Intel Software Day - Inferencia de IA em edge devices
 
Trilha BigData - Banco de Dados Orientado a Grafos na Seguranca Publica
Trilha BigData - Banco de Dados Orientado a Grafos na Seguranca PublicaTrilha BigData - Banco de Dados Orientado a Grafos na Seguranca Publica
Trilha BigData - Banco de Dados Orientado a Grafos na Seguranca Publica
 
Trilha .Net - Programacao funcional usando f#
Trilha .Net - Programacao funcional usando f#Trilha .Net - Programacao funcional usando f#
Trilha .Net - Programacao funcional usando f#
 
TDC2018SP | Trilha Go - Case Easylocus
TDC2018SP | Trilha Go - Case EasylocusTDC2018SP | Trilha Go - Case Easylocus
TDC2018SP | Trilha Go - Case Easylocus
 
TDC2018SP | Trilha Modern Web - Para onde caminha a Web?
TDC2018SP | Trilha Modern Web - Para onde caminha a Web?TDC2018SP | Trilha Modern Web - Para onde caminha a Web?
TDC2018SP | Trilha Modern Web - Para onde caminha a Web?
 
TDC2018SP | Trilha Go - Clean architecture em Golang
TDC2018SP | Trilha Go - Clean architecture em GolangTDC2018SP | Trilha Go - Clean architecture em Golang
TDC2018SP | Trilha Go - Clean architecture em Golang
 
TDC2018SP | Trilha Go - "Go" tambem e linguagem de QA
TDC2018SP | Trilha Go - "Go" tambem e linguagem de QATDC2018SP | Trilha Go - "Go" tambem e linguagem de QA
TDC2018SP | Trilha Go - "Go" tambem e linguagem de QA
 
TDC2018SP | Trilha Mobile - Digital Wallets - Seguranca, inovacao e tendencia
TDC2018SP | Trilha Mobile - Digital Wallets - Seguranca, inovacao e tendenciaTDC2018SP | Trilha Mobile - Digital Wallets - Seguranca, inovacao e tendencia
TDC2018SP | Trilha Mobile - Digital Wallets - Seguranca, inovacao e tendencia
 
TDC2018SP | Trilha .Net - Real Time apps com Azure SignalR Service
TDC2018SP | Trilha .Net - Real Time apps com Azure SignalR ServiceTDC2018SP | Trilha .Net - Real Time apps com Azure SignalR Service
TDC2018SP | Trilha .Net - Real Time apps com Azure SignalR Service
 
TDC2018SP | Trilha .Net - Passado, Presente e Futuro do .NET
TDC2018SP | Trilha .Net - Passado, Presente e Futuro do .NETTDC2018SP | Trilha .Net - Passado, Presente e Futuro do .NET
TDC2018SP | Trilha .Net - Passado, Presente e Futuro do .NET
 
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
 
TDC2018SP | Trilha .Net - Obtendo metricas com TDD utilizando build automatiz...
TDC2018SP | Trilha .Net - Obtendo metricas com TDD utilizando build automatiz...TDC2018SP | Trilha .Net - Obtendo metricas com TDD utilizando build automatiz...
TDC2018SP | Trilha .Net - Obtendo metricas com TDD utilizando build automatiz...
 
TDC2018SP | Trilha .Net - .NET funcional com F#
TDC2018SP | Trilha .Net - .NET funcional com F#TDC2018SP | Trilha .Net - .NET funcional com F#
TDC2018SP | Trilha .Net - .NET funcional com F#
 
TDC2018SP | Trilha .Net - Crie SPAs com Razor e C# usando Blazor em .Net Core
TDC2018SP | Trilha .Net - Crie SPAs com Razor e C# usando Blazor  em .Net CoreTDC2018SP | Trilha .Net - Crie SPAs com Razor e C# usando Blazor  em .Net Core
TDC2018SP | Trilha .Net - Crie SPAs com Razor e C# usando Blazor em .Net Core
 

Kürzlich hochgeladen

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Kürzlich hochgeladen (20)

UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

TDC2017 | São Paulo - Trilha Programação Funcional How we figured out we had a SRE team at - Problemas que o Elm resolve só com o compilador sem nada mais.

  • 1. Problemas que o Elm resolve só com o compilador sem nada mais @cuducos cuducos.me 1 / 73
  • 7. “O melhor caso de uso de Haskell” — Felipe de Morais 7 / 73
  • 9. Propriedades que podem não existir 1 9 / 73
  • 10. user = { name: 'Eduardo Cuducos', twitter: 'cuducos' } const getSocialMedia = (user) => user.facebook getSocialMedia(user) 10 / 73
  • 11. user = { name: 'Eduardo Cuducos', twitter: 'cuducos' } const getSocialMedia = (user) => user.facebook getSocialMedia(user) undefined 11 / 73
  • 12. class User: def __init__(self, name, twitter): self.name = name self.twitter = twitter user = User('Eduardo Cuducos', 'cuducos') def get_social_media(user): return user.facebook get_social_media(user) 12 / 73
  • 13. class User: def __init__(self, name, twitter): self.name = name self.twitter = twitter user = User('Eduardo Cuducos', 'cuducos') def get_social_media(user): return user.facebook get_social_media(user) AttributeError: 'User' object has no attribute 'facebook' 13 / 73
  • 14. type alias User = { name : String , twitter : String } getSocialMedia : User -> String getSocialMedia user = user.facebook 14 / 73
  • 15. type alias User = { name : String , twitter : String } getSocialMedia : User -> String getSocialMedia user = user.facebook -- TYPE MISMATCH ------------------------------------------------------ Main.elm `user` does not have a field named `facebook`. 15| user.facebook ^^^^^^^^^^^^^ The type of `user` is: User Which does not contain a field named `facebook`. Hint: The record fields do not match up. One has name and twitter. The other has facebook. 15 / 73
  • 16. type alias User = { name : String , twitter : String } getSocialMedia : User -> String getSocialMedia user = user.twitter 16 / 73
  • 17. type alias User = { name : String , twitter : String } getSocialMedia : User -> String getSocialMedia user = user.twitter Success! Compiled 1 module. 17 / 73
  • 18. Elm não te deixa com o undefined na mão! 18 / 73
  • 19. Objetos que podem não existir 2 19 / 73
  • 20. users = [ { name: 'Eduardo Cuducos', twitter: 'cuducos' }, { name: 'Hugo Bessa', twitter: 'hugobessaa' } ] const firstUserName = (users) => users[0].name firstUserName(users) 20 / 73
  • 21. users = [ { name: 'Eduardo Cuducos', twitter: 'cuducos' }, { name: 'Hugo Bessa', twitter: 'hugobessaa' } ] const firstUserName = (users) => users[0].name firstUserName(users) 'Eduardo Cuducos' 21 / 73
  • 23. users = [] firstUserName(users) TypeError: Cannot read property 'name' of undefined 23 / 73
  • 24. users = [ User('Eduardo Cuducos', 'cuducos'), User('Hugo Bessa', 'hugobessaa') ] def first_user_name(users): return users[0].name first_user_name(users) 24 / 73
  • 25. users = [ User('Eduardo Cuducos', 'cuducos'), User('Hugo Bessa', 'hugobessaa') ] def first_user_name(users): return users[0].name first_user_name(users) 'Eduardo Cuducos' 25 / 73
  • 27. users = [] first_user_name(users) IndexError: list index out of range 27 / 73
  • 28. users = [] first_user_name(users) IndexError: list index out of range def first_user_name(users): first_user, *_ = users return first_use.name 28 / 73
  • 29. users = [] first_user_name(users) IndexError: list index out of range def first_user_name(users): first_user, *_ = users return first_use.name ValueError: not enough values to unpack (expected at least 1, got 0) 29 / 73
  • 30. firstUserName : List User -> String firstUserName users = let firstUser = List.head users in firstUser.name 30 / 73
  • 31. firstUserName : List User -> String firstUserName users = let firstUser = List.head users in firstUser.name -- TYPE MISMATCH --------------------------------------------- Main.elm `firstUser` does not have a field named `name`. 29| firstUser.name ^^^^^^^^^^^^^^ The type of `firstUser` is: Maybe User Which does not contain a field named `name`. 31 / 73
  • 32. firstUserName : List User -> String firstUserName users = case List.head users of Just user -> user.name Nothing -> "User not found" 32 / 73
  • 33. firstUserName : List User -> String firstUserName users = case List.head users of Just user -> user.name Nothing -> "User not found" Success! Compiled 1 module. 33 / 73
  • 34. Elm te obri a a preparar a aplicação para casos raros, extremos! 34 / 73
  • 36. const tomorrow = (today) => parseInt(today) + 1 tomorrow('18') 36 / 73
  • 37. const tomorrow = (today) => parseInt(today) + 1 tomorrow('18') 19 37 / 73
  • 40. def tomorrow(today): return int(today) + 1 tomorrow('18') 40 / 73
  • 41. def tomorrow(today): return int(today) + 1 tomorrow('18') 19 41 / 73
  • 43. tomorrow(None) TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' 43 / 73
  • 44. tomorrow(None) TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' tomorrow('NaN') 44 / 73
  • 45. tomorrow(None) TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' tomorrow('NaN') ValueError: invalid literal for int() with base 10: 'NaN' 45 / 73
  • 46. tomorrow : String -> Int tomorrow today = (String.toInt today) + 1 46 / 73
  • 47. tomorrow : String -> Int tomorrow today = (String.toInt today) + 1 -- TYPE MISMATCH ------------------------------------------------------ Main.elm The left argument of (+) is causing a type mismatch. 45| (String.toInt today) + 1 ^^^^^^^^^^^^^^^^^^ (+) is expecting the left argument to be a: number But the left argument is: Result String Int 47 / 73
  • 48. tomorrow : String -> Int tomorrow today = case String.toInt today of Ok day -> day + 1 Err _ -> Debug.crash "TODO" 48 / 73
  • 49. tomorrow : String -> Int tomorrow today = case String.toInt today of Ok day -> day + 1 Err _ -> Debug.crash "TODO" Success! Compiled 1 module. 49 / 73
  • 50. Elm te obri a a se antecipar a erros em tempo de execução. 50 / 73
  • 51. Mas e o Debug.crash? 51 / 73
  • 52. view : String -> Html msg view today = case String.toInt today of Ok day -> viewMyApp Err error -> viewErroMsg error 52 / 73
  • 53. Ações de usuário não previstas 4 53 / 73
  • 54. ‑ 41 + 54 / 73
  • 55. const counter = (state, action) => { switch (action.type) { case 'INCREMENT': return state + 1 case 'DECREMENT': return state - 1 } } 55 / 73
  • 56. const counter = (state, action) => { switch (action.type) { case 'INCREMENT': return state + 1 case 'DECREMENT': return state - 1 } } const render = () => ReactDOM.render( <p> <button onClick={() => store.dispatch({ type: 'DECREMENT'})}>-</button> {store.getState()} <button onClick={() => store.dispatch({ type: 'INCREMENT'})}>+</button> </p> ) 56 / 73
  • 57. const counter = (state, action) => { switch (action.type) { case 'INCREMENT': return state + 1 case 'DECREMENT': return state - 1 } } const render = () => ReactDOM.render( <p> <button onClick={() => store.dispatch({ type: 'DECREMENT'})}>-</button> {store.getState()} <button onClick={() => store.dispatch({ type: 'INCREMENT'})}>+</button> </p> ) + 57 / 73
  • 58. const counter = (state, action) => { switch (action.type) { case 'INCREMENT': return state + 1 case 'DECREMENT': return state - 1 } } const render = () => ReactDOM.render( <p> <button onClick={() => store.dispatch({ type: 'DECREMENT'})}>-</button> {store.getState()} <button onClick={() => store.dispatch({ type: 'INCREMENT'})}>+</button> </p> ) + 42 58 / 73
  • 59. ‑ 21 + x2 59 / 73
  • 60. const render = () => ReactDOM.render( <p> <button onClick={() => store.dispatch({ type: 'DECREMENT'})}>-</button> {store.getSate()} <button onClick={() => store.dispatch({ type: 'INCREMENT'})}>+</button> <button onClick={() => store.dispatch({ type: 'DOUBLE'})}>x2</button> </p> ) 60 / 73
  • 61. const render = () => ReactDOM.render( <p> <button onClick={() => store.dispatch({ type: 'DECREMENT'})}>-</button> {store.getSate()} <button onClick={() => store.dispatch({ type: 'INCREMENT'})}>+</button> <button onClick={() => store.dispatch({ type: 'DOUBLE'})}>x2</button> </p> ) x2 61 / 73
  • 62. const render = () => ReactDOM.render( <p> <button onClick={() => store.dispatch({ type: 'DECREMENT'})}>-</button> {store.getSate()} <button onClick={() => store.dispatch({ type: 'INCREMENT'})}>+</button> <button onClick={() => store.dispatch({ type: 'DOUBLE'})}>x2</button> </p> ) x2 21 62 / 73
  • 63. type Msg = Increment | Decrement update : Msg -> Int -> Int update msg model = case msg of Increment -> model + 1 Decrement -> model - 1 view : Int -> Html Msg view model = p [] [ button [ onClick Increment ] [ text "+" ] , text (toString model) , button [ onClick Decrement ] [ text "-" ] ] 63 / 73
  • 64. type Msg = Increment | Decrement update : Msg -> Int -> Int update msg model = case msg of Increment -> model + 1 Decrement -> model - 1 view : Int -> Html Msg view model = p [] [ button [ onClick Increment ] [ text "+" ] , text (toString model) , button [ onClick Decrement ] [ text "-" ] ] ‑ 21 + 64 / 73
  • 65. view : Int -> Html Msg view model = p [] [ button [ onClick Increment ] [ text "+" ] , text (toString model) , button [ onClick Decrement ] [ text "-" ] , button [ onClick Double ] [ text "2x" ] ] 65 / 73
  • 66. view : Int -> Html Msg view model = p [] [ button [ onClick Increment ] [ text "+" ] , text (toString model) , button [ onClick Decrement ] [ text "-" ] , button [ onClick Double ] [ text "2x" ] ] -- NAMING ERROR ------------------------------------------------------- Main.elm Cannot find variable `Double` 82| , button [ onClick Double ] [ text "2x" ] 66 / 73
  • 67. type Msg = Increment | Decrement | Double 67 / 73
  • 68. type Msg = Increment | Decrement | Double -- MISSING PATTERNS --------------------------------------------------- Main.elm This `case` does not have branches for all possibilities. 68|> case msg of 69|> Increment -> 70|> model + 1 71|> 72|> Decrement -> 73|> model - 1 You need to account for the following values: Main.Double Add a branch to cover this pattern! 68 / 73
  • 69. update : Msg -> Int -> Int update msg model = case msg of Increment -> model + 1 Decrement -> model - 1 Double -> model * 2 69 / 73
  • 70. update : Msg -> Int -> Int update msg model = case msg of Increment -> model + 1 Decrement -> model - 1 Double -> model * 2 Success! Compiled 1 module. 70 / 73
  • 71. A arquitetura do Elm te dá arantia de que todas as ações dos usuários estão previstas! 71 / 73
  • 72. “Quem aprendeu al o novo hoje?” — Raymond Hettin er 72 / 73
  • 73. Muito obri ado : ) @cuducos cuducos.me/blo Vamos aprender Elm! 73 / 73