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. “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
  2. “All models are wrong” George E. P. Box "Robustness in

    the strategy of scientific model building", 1979, p. 202.
  3. “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.
  4. functional programming “2012 Chevrolet Cruze on the production line at

    Lordstown Assembly in Lordstown, Ohio” via GM
  5. “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
  6. 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
  7. “All models are wrong… George E. P. Box "Robustness in

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

    P. Box "Robustness in the strategy of scientific model building", 1979, p. 202.
  9. “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.
  10. 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.
  11. 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.
  12. 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.
  13. Adapted from J. Kerr, “Why Functional Matters: Your white board

    will never be the same”, 2012. Functional program flow
  14. 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.
  15. “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
  16. “... 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
  17. David Albert, Darius Bacon, Julia Evans & the Recurse Center

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