Slide 1

Slide 1 text

programming across paradigms @AnjanaVakil PolyConf 2017

Slide 2

Slide 2 text

hi, I’m @AnjanaVakil! The Recurse Center

Slide 3

Slide 3 text

1978 ACM Turing Award Lecture

Slide 4

Slide 4 text

“I believe the best chance we have to improve the general practice of programming is to attend to our paradigms.” Robert W. Floyd “The paradigms of programming.”, 1979. p. 456

Slide 5

Slide 5 text

what is a paradigm?

Slide 6

Slide 6 text

Front cover of 1st edition paperback (1962), via Wikimedia

Slide 7

Slide 7 text

a paradigm is a worldview

Slide 8

Slide 8 text

a paradigm is a model

Slide 9

Slide 9 text

“All models are wrong” George E. P. Box "Robustness in the strategy of scientific model building", 1979, p. 202.

Slide 10

Slide 10 text

“In learning a paradigm the scientist acquires theory, methods, and standards together, usually in an inextricable mixture.” Thomas S. Kuhn The Structure of Scientific Revolutions, (2nd ed.) 1970. p. 109.

Slide 11

Slide 11 text

theory what entities make up the universe how they behave and interact

Slide 12

Slide 12 text

methods & standards which problems are worth solving which solutions are legitimate

Slide 13

Slide 13 text

a paradigm enables progress

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

paradigm

Slide 16

Slide 16 text

Scenography of the Ptolemaic cosmography by Loon, J. van (Johannes), ca. 1611–1686. via Wikimedia

Slide 17

Slide 17 text

paradigm anomaly

Slide 18

Slide 18 text

paradigm anomaly crisis

Slide 19

Slide 19 text

paradigm anomaly crisis shift

Slide 20

Slide 20 text

Scenographia Systematis Copernicani (The Copernican System), 1686. via Wikimedia

Slide 21

Slide 21 text

paradigm anomaly crisis shift

Slide 22

Slide 22 text

what is programming?

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

imperative programming follow my commands in the order I give them remember state

Slide 25

Slide 25 text

imperative programming “Clocks Gears Wallpaper” via Wallpoper

Slide 26

Slide 26 text

object-oriented programming keep your state to yourself receive my messages respond as you see fit

Slide 27

Slide 27 text

object-oriented programming “Slide of the Week: Increased WBC, April 14, 2011” via Center for Genomic Pathology

Slide 28

Slide 28 text

functional programming mutable state is dangerous pure functions are safe data goes in data comes out

Slide 29

Slide 29 text

functional programming “2012 Chevrolet Cruze on the production line at Lordstown Assembly in Lordstown, Ohio” via GM

Slide 30

Slide 30 text

declarative programming these are the facts this is what i want i don’t care how you do it

Slide 31

Slide 31 text

declarative programming “Sudoku05” by Jelte (CC BY-SA 3.0) via Wikimedia

Slide 32

Slide 32 text

https://www.info.ucl.ac.be/~pvr/paradigms.html

Slide 33

Slide 33 text

are they really so different?

Slide 34

Slide 34 text

shared mutable state

Slide 35

Slide 35 text

shared mutable state

Slide 36

Slide 36 text

shared mutable state

Slide 37

Slide 37 text

shared mutable state

Slide 38

Slide 38 text

“I'm sorry that I long ago coined the term "objects" for this topic because it gets many people to focus on the lesser idea. The big idea is "messaging".” Alan Kay Message to Smalltalk/Squeak mailing list, 1998

Slide 39

Slide 39 text

message ↓ response

Slide 40

Slide 40 text

input ↓ output

Slide 41

Slide 41 text

behavior

Slide 42

Slide 42 text

Lambda calculus TRUE := λx.λy.x FALSE := λx.λy.y Smalltalk class True ifTrue: a ifFalse: b ^ a value class False ifTrue: a ifFalse: b ^ b value

Slide 43

Slide 43 text

which paradigm is The Best?

Slide 44

Slide 44 text

“All models are wrong… George E. P. Box "Robustness in the strategy of scientific model building", 1979, p. 202.

Slide 45

Slide 45 text

“All models are wrong but some are useful” George E. P. Box "Robustness in the strategy of scientific model building", 1979, p. 202.

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

“Is the model true?” “Is the model illuminating and useful?” George E. P. Box "Robustness in the strategy of scientific model building", 1979, p. 202.

Slide 48

Slide 48 text

what can a paradigm illuminate?

Slide 49

Slide 49 text

be explicit focus on implementation be machine-efficient

Slide 50

Slide 50 text

Rust for Elixir: NIFty! #[macro_use] extern crate rustler; #[macro_use] extern crate rustler_codegen; #[macro_use] extern crate lazy_static; use rustler::{NifEnv, NifTerm, NifResult, NifEncoder}; mod atoms { rustler_atoms! { atom ok; } } rustler_export_nifs! { "Elixir.Testing.MyNif", [("add", 2, add)], None } fn add<'a>(env: NifEnv<'a>, args: &[NifTerm<'a>]) -> NifResult> { let num1: i64 = args[0].decode()?; let num2: i64 = args[1].decode()?; // complicated math here // such imperative, so performance, wow Ok((atoms::ok(), result).encode(env)) } Adapted from H.E.B. Josephsen, “Elixir FFI with Rust”, PolyConf 2017.

Slide 51

Slide 51 text

be abstract focus on domain be human-efficient

Slide 52

Slide 52 text

Embedded DSL in Java cal = new Calendar(); cal.event("PolyConf") .on(2017, 07, 09) .from("09:00") .to("19:00") .at("La Géode"); Adapted from M. Fowler & R. Parsons, Domain Specific Languages, 2011, p. 345.

Slide 53

Slide 53 text

encapsulate remember

Slide 54

Slide 54 text

Context-aware API in F# module MyApi = let fnA dep1 dep2 dep3 arg1 = doAWith dep1 dep2 dep3 arg1 let fnB dep1 dep2 dep3 arg2 = doBWith dep1 dep2 dep3 arg2 type MyParametricApi(dep1, dep2, dep3) = member __.FnA arg1 = doAWith dep1 dep2 dep3 arg1 member __.FnB arg2 = doBWith dep1 dep2 dep3 arg2 Adapted from E. Tsarpalis, “Why OOP Matters (in F#)”, 2017.

Slide 55

Slide 55 text

isolate transform

Slide 56

Slide 56 text

Adapted from J. Kerr, “Why Functional Matters: Your white board will never be the same”, 2012. Functional program flow

Slide 57

Slide 57 text

Each paradigm supports a set of concepts that makes it the best for a certain kind of problem. Peter Van Roy “Programming paradigms for dummies: What every programmer should know”, 2009, p. 10.

Slide 58

Slide 58 text

no paradigm is best absolutely each is best for a certain case

Slide 59

Slide 59 text

multi-paradigm languages give you options

Slide 60

Slide 60 text

what’s the point?

Slide 61

Slide 61 text

paradigms enable programming

Slide 62

Slide 62 text

paradigms define programming

Slide 63

Slide 63 text

embrace your paradigm, don’t fight it

Slide 64

Slide 64 text

be open to shift

Slide 65

Slide 65 text

“If the advancement of the general art of programming requires the continuing invention and elaboration of paradigms...” Robert W. Floyd “The paradigms of programming.”, 1979. p. 456

Slide 66

Slide 66 text

“... advancement of the art of the individual programmer requires that [t]he[y] expand [their] repertory of paradigms.” Robert W. Floyd “The paradigms of programming.”, 1979. p. 456

Slide 67

Slide 67 text

learn new paradigms invent new paradigms

Slide 68

Slide 68 text

let’s attend to our paradigms

Slide 69

Slide 69 text

David Albert, Darius Bacon, Julia Evans & the Recurse Center PolyConf organizers thank you! @AnjanaVakil

Slide 70

Slide 70 text

References & further reading/watching Box, George E.P. (1979), "Robustness in the strategy of scientific model building", in Launer & Wilkinson, Robustness in Statistics, Academic Press, pp. 201–236. Cook, William (2012). “A Proposal for Simplified, Modern Definitions of ‘Object’ and ‘Object Oriented’”. wcook.blogspot.fr/2012/07/proposal-for-simplified-modern.html Floyd, Robert W. (1979). “The paradigms of programming.” Commun. ACM 22, 8, 455-460. Fowler, Martin, with Parsons, Rebecca. (2011). Domain Specific Languages. Addison-Wesley. Josephsen, Hans Elias Bukholm (2017). “Elixir FFI with Rust”, PolyConf. http://slides.com/hansihe/rustler#/ Kay, Alan (1998). Message to Smalltalk/Squeak mailing list. wiki.c2.com/?AlanKayOnMessaging Kerr, Jessica (2012). “Why Functional Matters: Your white board will never be the same”. blog.jessitron.com/2012/06/why-functional-matters-your-white-board.html Kerr, Jessica (2014). “Functional Principles for Object-Oriented Development”, GOTO Chicago. https://youtu.be/GpXsQ-NIKXY Kuhn, Thomas S. (1970). The Structure of Scientific Revolutions. (2nd ed.). University of Chicago Press. Tsarpalis, Eirik. (2017). “Why OO matters (in F#)”. https://eiriktsarpalis.wordpress.com/2017/03/20/why-oo-matters-in-f/ Van Roy, Peter. (2009). “Programming paradigms for dummies: What every programmer should know.” In New computational paradigms for computer music, p. 104. Williams, Ashley. (2015). “If you wish to learn ES6/2015 from scratch, you must first invent the universe”, JSConf. https://youtu.be/DN4yLZB1vUQ