Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Programming across paradigms

Programming across paradigms

Presented at PolyConf 2017: https://polyconf.com/

The programming paradigm we work in shapes every aspect of how we craft our code, providing a model of what a program is, and what it can and should be. In this talk, we’ll explore the connections between the programs we write, the languages we work in, and the paradigms we use, and try to get some historical and philosophical perspective on the familiar paradigms of imperative, declarative, object-oriented, and functional programming, focusing on the points where they intersect and collide. We’ll discover the valuable lessons different paradigms can teach us, and find motivation to stop arguing with our fellow coders about which is superior, and instead encourage each other - as individuals and a community - to pursue poly-paradigm programming.

Anjana Sofia Vakil

July 09, 2017
Tweet

More Decks by Anjana Sofia Vakil

Other Decks in Programming

Transcript

  1. programming across
    paradigms
    @AnjanaVakil
    PolyConf 2017

    View Slide

  2. hi, I’m @AnjanaVakil!
    The
    Recurse
    Center

    View Slide

  3. 1978 ACM Turing Award Lecture

    View Slide

  4. “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

    View Slide

  5. what is a
    paradigm?

    View Slide

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

    View Slide

  7. a paradigm is a worldview

    View Slide

  8. a paradigm is a model

    View Slide

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

    View Slide

  10. “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.

    View Slide

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

    View Slide

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

    View Slide

  13. a paradigm enables progress

    View Slide

  14. View Slide

  15. paradigm

    View Slide

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

    View Slide

  17. paradigm
    anomaly

    View Slide

  18. paradigm
    anomaly
    crisis

    View Slide

  19. paradigm
    anomaly
    crisis
    shift

    View Slide

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

    View Slide

  21. paradigm
    anomaly
    crisis
    shift

    View Slide

  22. what is
    programming?

    View Slide

  23. View Slide

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

    View Slide

  25. imperative
    programming
    “Clocks Gears Wallpaper” via Wallpoper

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  33. are they really
    so different?

    View Slide

  34. shared
    mutable state

    View Slide

  35. shared
    mutable state

    View Slide

  36. shared
    mutable state

    View Slide

  37. shared
    mutable state

    View Slide

  38. “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

    View Slide

  39. message

    response

    View Slide

  40. input

    output

    View Slide

  41. behavior

    View Slide

  42. 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

    View Slide

  43. which paradigm is
    The Best?

    View Slide

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

    View Slide

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

    View Slide

  46. View Slide

  47. “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.

    View Slide

  48. what can a paradigm
    illuminate?

    View Slide

  49. be explicit
    focus on implementation
    be machine-efficient

    View Slide

  50. 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(env: NifEnv, args: &[NifTerm]) -> 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.

    View Slide

  51. be abstract
    focus on domain
    be human-efficient

    View Slide

  52. 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.

    View Slide

  53. encapsulate
    remember

    View Slide

  54. 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.

    View Slide

  55. isolate
    transform

    View Slide

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

    View Slide

  57. 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.

    View Slide

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

    View Slide

  59. multi-paradigm languages
    give you options

    View Slide

  60. what’s the
    point?

    View Slide

  61. paradigms enable programming

    View Slide

  62. paradigms define programming

    View Slide

  63. embrace your paradigm,
    don’t fight it

    View Slide

  64. be open to shift

    View Slide

  65. “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

    View Slide

  66. “... 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

    View Slide

  67. learn new paradigms
    invent new paradigms

    View Slide

  68. let’s attend to our paradigms

    View Slide

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

    View Slide

  70. 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

    View Slide