E Pluribus Unum: A Survey of Multi-paradigm Programming

587 views

Published on

Video and slides synchronized, mp3 and slide download available at http://bit.ly/16EPuys.

Paul Snively outlines the benefits of programming with multi-paradigm languages such as Scala, C++ or OCaml.Filmed at qconnewyork.com.

Paul Snively is a 30-year veteran of the software development industry with a passion for programming languages, physics, and math. He's developed everything from games to word processors to educational software to investment advice systems to e-commerce systems in at least half a dozen languages. Paul uses Scala on the job in the Cloud Infrastructure Engineering group at VMware.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
587
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

E Pluribus Unum: A Survey of Multi-paradigm Programming

  1. 1. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively June 12, 2013
  2. 2. InfoQ.com: News & Community Site • 750,000 unique visitors/month • Published in 4 languages (English, Chinese, Japanese and Brazilian Portuguese) • Post content from our QCon conferences • News 15-20 / week • Articles 3-4 / week • Presentations (videos) 12-15 / week • Interviews 2-3 / week • Books 1 / month Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations /polyglot-scala-c-plus-plus-ocaml
  3. 3. Presented at QCon New York www.qconnewyork.com Purpose of QCon - to empower software development by facilitating the spread of knowledge and innovation Strategy - practitioner-driven conference designed for YOU: influencers of change and innovation in your teams - speakers and topics driving the evolution and innovation - connecting and catalyzing the influencers and innovators Highlights - attended by more than 12,000 delegates since 2007 - held in 9 cities worldwide
  4. 4. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary "The Right Tool for the Job" Java/Ruby/PHP JavaScript SQL/Hive/Pig . . . & Objective-C if you work on iOS
  5. 5. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary What Are Paradigms? a philosophical and theoretical framework of a scientific school or discipline within which theories, laws, and generalizations and the experiments performed in support of them are formulated; broadly : a philosophical or theoretical framework of any kind — Merriam-Webster Dictionary
  6. 6. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary Popular Paradigms There are lots—see the Wikipedia page Bodil Stokke: What Every Hipster Should Know About Functional Programming • Imperative • Object-Oriented • Functional • Relational Dataflow
  7. 7. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary Each Language Expresses a Paradigm OO Domain Modeling in Java/Ruby/PHP Relational(ish) Queries in SQL/Hive/Pig Events and callbacks (Functional) in JavaScript
  8. 8. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary Pros Lots of Task-Specific Frameworks Abundant Documentation Robust Developer Communities
  9. 9. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary Cons Silos XSS/Injection Attacks Task Fit Oversold (e.g. OO for UI)
  10. 10. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary Functional Programming Functions as Primary Abstraction Unit • Daniel Spiewak: Living in a Post-Functional World Traditional Bogeyman vs. OO • False Dichotomy: Scala, OCaml both OO/FP • Martin Odersky: Objects and Functions: Conflict Without a Cause?
  11. 11. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary Functional Programming in OCaml let id ic oc = let i = Xmlm.make_input (‘Channel ic) in let o = Xmlm.make_output (‘Channel oc) in let rec pull i o depth = Xmlm.output o (Xmlm.peek i); match Xmlm.input i with | ‘El_start _ -> pull i o (depth + 1) | ‘El_end -> if depth = 1 then () else pull i o (depth - 1) | ‘Data _ -> pull i o depth | ‘Dtd _ -> assert false in Xmlm.output o (Xmlm.input i); (* ‘Dtd *) pull i o 0; if not (Xmlm.eoi i) then invalid_arg "document not well-formed" Listing 1: Copy an XML document from an input channel to an output channel
  12. 12. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary Functional Programming in Scala Stream.continually( util.Random.nextInt(6) + util.Random.nextInt(6) + 2 ) .take(200) .groupBy(identity) .toList .sortBy(_._1) .foreach { case(a, b) => println(a + ":" + "X" * b.size) } Listing 2: ASCII Histogram of 200 Rolls of a Pair of Dice
  13. 13. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary Functional Programming. . . in C++!? int x = 10; std::vector<std::vector<int> > v(10); for_each(arg1, lambda(_a = arg2) [ push_back(arg1, _a) ] ) (v, x); Listing 3: Build a Vector of 10 Vectors of 10’s.
  14. 14. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary Relational Programming. . . in C++!? // Rule defining the meaning of a path relation path(lref<int> start, lref<int> end) { lref<int> nodeX; return edge(start, end) || edge(start, nodeX) && recurse(path, nodeX, end); } Listing 4: The Path Relation Connecting Graph Nodes With Edges
  15. 15. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary Relational Programming. . . in Scala!? private def common_prefix_o(l: Any, l1: Any, l2: Any): Goal = { if_i(null_o(l), succeed, { s: Subst => { val x = make_var(’x) val ls = make_var(’ls) val l1s = make_var(’l1s) val l2s = make_var(’l2s) all(l === (x, ls), l1 === (x, l1s), l2 === (x, l2s), common_prefix_o(ls, l1s, l2s))(s) } }) } Listing 5: The Common Prefix Relation of Three Sequences
  16. 16. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary Dataflow Programming. . . in Scala!? val v1, v2 = Promise[Int]() flow { // v1 will become the value of v2 + 10 when v2 gets a value v1 << v2() + 10 v1() + v2() } onComplete println flow { v2 << 5 } // As you can see, no blocking above! Listing 6: Promises as dataflow variables
  17. 17. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary Dataflow Programming. . . in C++!? signals::timed_generator<void (double)> input(0); processor proc; output out; input >>= proc >>= out; input.enable(0.5); boost::xtime xt; boost::xtime_get(&xt, boost::TIME_UTC); xt.sec += 10; boost::thread::sleep(xt); input.join(); Listing 7: Periodically generate a signal, add Gaussian noise, and output
  18. 18. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary OPA import stdlib.themes.bootstrap database int /counter = 0; function action(_) { /counter++; #msg = <div>Thank you, user number {/counter}!</div> } function page() { <h1 id="msg">Hello</h1> <a class="btn" onclick={action}>Click me</a> } Server.start( Server.http, { ~page, title: "Database Demo" } ) Listing 8: A web page with a persistent user counter
  19. 19. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary Ur/Web fun list () = rows <- queryX (SELECT * FROM t) (fn row => <xml><tr> <td>{[row.T.A]}</td> <td>{[row.T.B]}</td> <td>{[row.T.C]}</td> <td>{[row.T.D]}</td> <td> <form> <submit action={delete row.T.A} value="Delete"/> </form> </td> </tr></xml>); return <xml> <table border=1> <tr> <th>A</th> <th>B</th> <th>C</th> <th>D</th> </tr> {rows} </table> ... Listing 9: List rows from the database in a table
  20. 20. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary SLICK Relational Programming as Functional Programming Persons .sortBy(_.name) .drop(5).take(10) Listing 10: Sort Persons by name, then drop the first 5 and take the next 10
  21. 21. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary Functional Reactive Programming With RxJS var mousedrag = mousedown.selectMany(function (md) { var startX = md.offsetX, startY = md.offsetY; return mousemove.select(function (mm) { (mm.preventDefault) ? mm.preventDefault() : event.returnValue = false; return { left: mm.clientX - startX, top: mm.clientY - startY }; }).takeUntil(mouseup); }); subscription = mousedrag.subscribe(function (pos) { dragTarget.style.top = pos.top + ’px’; dragTarget.style.left = pos.left + ’px’; }); Listing 11: Drag-and-drop
  22. 22. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary BYOP If you can’t use a multiparadigm language, use a metaparadigm one • Your "EDSL" should present a different paradigm, otherwise what’s the point? • Macros • Delimited Continuations • Hint: Scala 2.10+ is such a language
  23. 23. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary Platform Matters • A multiparadigm language that compiles to x86_64, ARM v7, and JavaScript is a very long lever • Especially if there are already libraries for developing hypervisor kernels, webapps, iOS, and Android apps • Hint: OCaml is such a language • Managers: this means the most popular technology is very unlikely to be the right technology
  24. 24. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary Takeaways • We do polyglot programming partially due to accidents of history and partially to use multiple paradigms • Focusing on paradigms instead of languages obviates entire classes of issues, especially security issues • Pick a good multiparadigm language and you can be in the cloud, in the browser, on iOS, and on Android with a single language. • Build a good team with that one language and you can do it with 5-7 developers • Managers: this means moving past the developer-as-fungible-resource mindset
  25. 25. E Pluribus Unum: A Survey of Multiparadigm Programming Paul Snively Polyglot Programming Multiparadigm Programming Functional Programming Relational Programming Dataflow Programming All-in-One Webapps Shapeshifting Summary Questions?

×