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


  1. programming across paradigms @AnjanaVakil PolyConf 2017

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

  3. 1978 ACM Turing Award Lecture

  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
  5. what is a paradigm?

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

  7. a paradigm is a worldview

  8. a paradigm is a model

  9. “All models are wrong” George E. P. Box "Robustness in

    the strategy of scientific model building", 1979, p. 202.
  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.
  11. theory what entities make up the universe how they behave

    and interact
  12. methods & standards which problems are worth solving which solutions

    are legitimate
  13. a paradigm enables progress

  14. None
  15. paradigm

  16. Scenography of the Ptolemaic cosmography by Loon, J. van (Johannes),

    ca. 1611–1686. via Wikimedia
  17. paradigm anomaly

  18. paradigm anomaly crisis

  19. paradigm anomaly crisis shift

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

  21. paradigm anomaly crisis shift

  22. what is programming?

  23. None
  24. imperative programming follow my commands in the order I give

    them remember state
  25. imperative programming “Clocks Gears Wallpaper” via Wallpoper

  26. object-oriented programming keep your state to yourself receive my messages

    respond as you see fit
  27. object-oriented programming “Slide of the Week: Increased WBC, April 14,

    2011” via Center for Genomic Pathology
  28. functional programming mutable state is dangerous pure functions are safe

    data goes in data comes out
  29. functional programming “2012 Chevrolet Cruze on the production line at

    Lordstown Assembly in Lordstown, Ohio” via GM
  30. declarative programming these are the facts this is what i

    want i don’t care how you do it
  31. declarative programming “Sudoku05” by Jelte (CC BY-SA 3.0) via Wikimedia

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

  33. are they really so different?

  34. shared mutable state

  35. shared mutable state

  36. shared mutable state

  37. shared mutable state

  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
  39. message ↓ response

  40. input ↓ output

  41. behavior

  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
  43. which paradigm is The Best?

  44. “All models are wrong… George E. P. Box "Robustness in

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

    P. Box "Robustness in the strategy of scientific model building", 1979, p. 202.
  46. None
  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.
  48. what can a paradigm illuminate?

  49. be explicit focus on implementation be machine-efficient

  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<'a>(env: NifEnv<'a>, args: &[NifTerm<'a>]) -> NifResult<NifTerm<'a>> { 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.
  51. be abstract focus on domain be human-efficient

  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.
  53. encapsulate remember

  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.
  55. isolate transform

  56. Adapted from J. Kerr, “Why Functional Matters: Your white board

    will never be the same”, 2012. Functional program flow
  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.
  58. no paradigm is best absolutely each is best for a

    certain case
  59. multi-paradigm languages give you options

  60. what’s the point?

  61. paradigms enable programming

  62. paradigms define programming

  63. embrace your paradigm, don’t fight it

  64. be open to shift

  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
  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
  67. learn new paradigms invent new paradigms

  68. let’s attend to our paradigms

  69. David Albert, Darius Bacon, Julia Evans & the Recurse Center

    PolyConf organizers thank you! @AnjanaVakil
  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