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 full-size slide

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

    View full-size slide

  3. 1978 ACM Turing Award Lecture

    View full-size 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 full-size slide

  5. what is a
    paradigm?

    View full-size slide

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

    View full-size slide

  7. a paradigm is a worldview

    View full-size slide

  8. a paradigm is a model

    View full-size slide

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

    View full-size 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 full-size slide

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

    View full-size slide

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

    View full-size slide

  13. a paradigm enables progress

    View full-size slide

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

    View full-size slide

  15. paradigm
    anomaly

    View full-size slide

  16. paradigm
    anomaly
    crisis

    View full-size slide

  17. paradigm
    anomaly
    crisis
    shift

    View full-size slide

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

    View full-size slide

  19. paradigm
    anomaly
    crisis
    shift

    View full-size slide

  20. what is
    programming?

    View full-size slide

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

    View full-size slide

  22. imperative
    programming
    “Clocks Gears Wallpaper” via Wallpoper

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  30. are they really
    so different?

    View full-size slide

  31. shared
    mutable state

    View full-size slide

  32. shared
    mutable state

    View full-size slide

  33. shared
    mutable state

    View full-size slide

  34. shared
    mutable state

    View full-size slide

  35. “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 full-size slide

  36. message

    response

    View full-size slide

  37. input

    output

    View full-size slide

  38. 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 full-size slide

  39. which paradigm is
    The Best?

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  42. “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 full-size slide

  43. what can a paradigm
    illuminate?

    View full-size slide

  44. be explicit
    focus on implementation
    be machine-efficient

    View full-size slide

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

    View full-size slide

  46. be abstract
    focus on domain
    be human-efficient

    View full-size slide

  47. 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 full-size slide

  48. encapsulate
    remember

    View full-size slide

  49. 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 full-size slide

  50. isolate
    transform

    View full-size slide

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

    View full-size slide

  52. 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 full-size slide

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

    View full-size slide

  54. multi-paradigm languages
    give you options

    View full-size slide

  55. what’s the
    point?

    View full-size slide

  56. paradigms enable programming

    View full-size slide

  57. paradigms define programming

    View full-size slide

  58. embrace your paradigm,
    don’t fight it

    View full-size slide

  59. be open to shift

    View full-size slide

  60. “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 full-size slide

  61. “... 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 full-size slide

  62. learn new paradigms
    invent new paradigms

    View full-size slide

  63. let’s attend to our paradigms

    View full-size slide

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

    View full-size slide

  65. 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 full-size slide