Making life easier with just types and functions
-
Upload
chandan-singh -
Category
Documents
-
view
39 -
download
2
Transcript of Making life easier with just types and functions
![Page 1: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/1.jpg)
MAKING LIFE EASIER WITH JUST TYPES AND
FUNCTIONSCHANDAN SINGH
ThoughtWorks
![Page 2: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/2.jpg)
![Page 3: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/3.jpg)
the curse of functional programming!
once you understand it well enough, you lose the ability to explain it to others...
![Page 4: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/4.jpg)
why (typed) functional programming?
it looks cool on your résumé!
![Page 5: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/5.jpg)
complaints against FP?
it’s weird,impractical,why do it when OO/Procedural just works?theoretical/academic nonsense,no one really does it
![Page 6: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/6.jpg)
who’s doing FP?Facebook,Twitter,LinkedIn,Microsoft,Chef,Many banks...also, ThoughtWorks
![Page 7: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/7.jpg)
There’s something about the culture of software that has impeded the use of specification. We have a wonderful way of describing things precisely that has been developed over the last couple of millennia, and it’s called Mathematics.-- Leslie Lamport, Turing Award Winner, 2013.
![Page 8: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/8.jpg)
what does FP bring to the table?
good codeeasy to readeasy to understandeasy to testeasy to maintaineasy to extend
![Page 9: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/9.jpg)
insanity!
doing the same thing over and over again, and expecting different results!
--Albert Einstein
launchMissiles();=> destroys enemy units
launchMissiles();=> throws OutOfMissilesException
![Page 10: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/10.jpg)
what is FP?
lambda calculusid(x) = x
x -> xsquare_sum(x, y) = x * x + y * y
(x, y) -> x * x + y * yx -> (y -> (x * x + y * y))
![Page 11: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/11.jpg)
confused? let’s make it simple!
pure functions, no side effectsalso, higher order functions
![Page 12: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/12.jpg)
what’s a function?
a mapping,each input mapped to exactly one output,
domain co-domain
![Page 13: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/13.jpg)
functions are inherently typed
meaningful mappings,transformation rules => constraints,
capture constraints precisely
![Page 14: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/14.jpg)
public Integer square(Integer n) {
n = n * n;
return n;
}mutation, side effecting => impure
public Integer square(Integer n) {
return n * n;
}
no side effect, does only one thing => pure
![Page 15: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/15.jpg)
impure stuff
setters,
void/unit methods,
in-memory updates,
random()
![Page 16: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/16.jpg)
what’s wrong with impure stuff?
contextual dependencystate changes
order of execution is importantfar too much guessing to be done
![Page 17: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/17.jpg)
stop talking, show some code!
![Page 18: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/18.jpg)
so why is this FP suddenly a rage?
concurrency ...immutability, ftw!
![Page 19: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/19.jpg)
code, code, more code...
![Page 20: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/20.jpg)
so again, why (typed) FP?
making things easier,programming with less effort,
developer happiness!
![Page 21: Making life easier with just types and functions](https://reader031.fdocuments.us/reader031/viewer/2022020410/587191441a28ab2c198b779f/html5/thumbnails/21.jpg)
thank you!