Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Mike Kotsur - What can philosophy teach us about programming - Codemotion Amsterdam 2019

10 views

Published on

If Socrates met Linus Torvalds, what would they talk about? How much math should be bundled into a good programming language? Can compiler resolve an argument and prove, that someone is right? Trough semantics of code, that we write every day, when looking carefully, one can see foundations of logic and science, that has been build more than 2000 years ago. Why does it matter, and how can we leverage this enormous power to make our code safe and sound in languages with advanced type systems, like Typescript and Scala.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Mike Kotsur - What can philosophy teach us about programming - Codemotion Amsterdam 2019

  1. 1. What can philosophy teach us about programming Mike Kotsur Amsterdam | April 2-3, 2019
  2. 2. 👋 Mike Kotsur • Father, blogger, climber, tech lead. • https://github.com/mkotsur/ • Specialist degree in applied math; • 10+ years coding; • “Native” languages: PHP, Java, Javascript,Typescript, Scala. • Work: Startups, Marktplaats/eBay, XebiaLabs, Elsevier.
  3. 3. Douglas R. Hofstadter, Gödel, Escher, Bach James R. Newman, The World of Mathematics Immanuel Kant, Kritik der reinen Vernunft
  4. 4. confidence
  5. 5. Alex Honold scaling El Capitan (914m) without safety rope
  6. 6. Program Project Language Program Knowledge Language Standard way of thinking
  7. 7. Program Project Language Program Knowledge Language Thinking from first principles Painful Learning
  8. 8. Pythagoras (570 – 495 BC) • Founder of Pythagoreanism; • The first man to call himself a philosopher ("lover of wisdom”); • One of the earliest vegetarians.
  9. 9. Socrates (570 – 495 BC) • Famous by Plato’s dialogues; • One of the founders of Western philosophy; • Socratic method
  10. 10. - Teacher:What is happening to our global climate? - Stan: It’s getting warmer. - Teacher: How do you know it’s getting warmer? What evidence do you have to support your answer? - Stan: We have all of these record heat days. - Teacher: How do you know this is true? - Stan: Scientists are saying that - Teacher: How would they know? - Stan:They have special equipment. Source: Intel Tech Program, Designing Effective Projects
  11. 11. Socratic method • False ignorance • Goading (provoking, often by questions) • Exposing fundamental premises • Showing contradictions
  12. 12. Aristotle (470 – 399 BC) • Along with Plato, he is considered the "Father of Western Philosophy”; • Defined syllogisms and introduced Aristotelian logic;
  13. 13. Syllogisms and term logic - No reptiles have fur; - All snakes are reptiles; - Therefore, no snakes have fur. - No R have F; - All S are R; - Therefore, no S have F.
  14. 14. P: No one is free who has not obtained the empire of himself. M: I started the site when I was 19. I didn't know much about business back then. S: The unexamined life is not worth living L: Talk is cheap. Show me the code. A: Let’s use symbols! For instance: Every C is B Every C is A So, some A is B H: Program is a proof Pythagoras M. Zuckerberg L.Torwalds H. CurryAristotle Socrates
  15. 15. Hey, Haskell, tell me more. What do you mean by a “program is a proof” ??? 🤔 A moment ago Haskell is typing…
  16. 16. That language is an instrument of human reason, and not merely a medium for the expression of thought, is a truth generally admitted. George Boole (1815 - 1864) It is unworthy of excellent men to lose hours like slaves in the labour of calculation which could safely be relegated to anyone else if machines were used. Gottfried Wilhelm Leibniz (1646 - 1716) Yo! Check out those dudes 👇 A moment ago
  17. 17. A moment ago
  18. 18. A moment ago
  19. 19. Impressive! So people don’t make those stupid logical mistakes anymore? 😈 20 seconds ago %They do, but we’ve learned a lot… 10 seconds ago
  20. 20. Argument validity Impossible for the premises to be true and the conclusion false at the same time ✤ Animals that fly can live in trees ✤ Cats can fly ✤ Therefore cats can live in trees
  21. 21. Argument soundness Not only valid, but the premises are actually true ✤ Animals that fly can live in trees ✤ Cats can not fly ✤ Therefore cats can not live in trees
  22. 22. After this, therefore because of this (Post Hoc, Ergo Propter Hoc) Right when I sneezed, the power went off. I must’ve caused the outage.
  23. 23. Genetic Fallacy ✤ Ha! I’m not reading that book. ✤ It was published inTennessee, and we know allTennessee folk are hillbillies and rednecks!
  24. 24. Circular reasoning You can’t get a job without experience, and you can’t get experience without a job.
  25. 25. Argument from force (Argumentum ad Baculum) ✤ You say there’s no way you can finish the project next week? ✤ Bullshit! Find a way! Make it happen! Just do it! ✤ This is a million dollar contract and we need it done byTuesday.
  26. 26. Slippery slope
  27. 27. Yes, talk is cheap, show me the code! But what about programming?
  28. 28. Curry-Howard isomorphism In order to prove any mathematical theorem, all we have to do is construct a certain type which reflects the nature of that theorem, then find a value that has that type.
  29. 29. Math Computer science Proofs Formulas Programs Types A implies B A and B A or B Function from A => B Tuple of A and B Union of A and B falsity truth empty type singleton type Axiom Soundness Theorem Completeness Theorem Incompleteness Theorem System Primitive Compiler Debugger Infinite loop
  30. 30. Math Computer science Double negation First class callbacks Friedman’s translation Dynamic Exceptions Cohen’s Forcing Global Variables Dialectica Translation Scoped goto’s (e.g. Python’s yield)
  31. 31. So, we are using math to describe the world.What are you using your software stuff for? 3 minutes ago We kind of create a virtual world with our own rules… 20 seconds ago Wow, how far you have gone! A moment ago
  32. 32. I bet your tools guarantee that errors like in those arguments can never even happen in this new world. A minute ago I wish… A moment ago
  33. 33. Paradigm Description Imperative, Structured, Procedural Programs as statements that directly change computed state (datafields). Also with procedure calls. Functional Treats computation as the evaluation of mathematical functions avoiding state and mutable data Event-driven Control flow is determined mainly by events, such as mouse clicks or interrupts including timer Object-oriented Treats datafields as objects manipulated through predefined methods only Declarative Defines program logic, but not detailed control flow Automata-based programming Treats programs as a model of a finite state machine or any other formal automata PROGRAMMING PARADIGMS Source:Wikipedia:Comparisonofprogrammingparadigms
  34. 34. Source: https://github.com/denysdovhan/wtfjs [] == ![]; // -> true true == []; // -> false true == ![]; // -> false false == []; // -> true false == ![]; // -> true NaN === NaN; // -> false WTF JS
  35. 35. Source: https://github.com/denysdovhan/wtfjs document.all instanceof Object; // -> true typeof document.all; // -> 'undefined' Number.MIN_VALUE > 0; // -> true WTF JS
  36. 36. Source: https://github.com/satwikkansal/wtfpython >>> a = "wtf" >>> b = "wtf" >>> a is b True >>> a = "wtf!" >>> b = "wtf!" >>> a is b False WTF Python
  37. 37. Source: https://github.com/satwikkansal/wtfpython WTF Python some_dict = {} some_dict[5.5] = "Ruby" some_dict[5.0] = "JavaScript" some_dict[5] = "Python" >>> some_dict[5.5] "Ruby" >>> some_dict[5.0] "Python" >>> some_dict[5] "Python"
  38. 38. WTF JS 53 WTF Python 51 &
  39. 39. Uh…That hurts my ancient geek brain! 5 seconds ago Why would people do this?
  40. 40. “When it gets hard, we build more escape hatches and tell users to be careful.” Amal Ahmed,All The Languages Together. Presented at Strange Loop 2018
  41. 41. “I made up the term object- oriented, and I can tell you I did not have C++ in mind.” Alan Kay, has designed a few programming languages
  42. 42. difficult
  43. 43. different difficult
  44. 44. A change of perspective is worth 80 IQ points Alan Kay
  45. 45. All good counsel begins in the same way; a man should know what he is advising about, or his counsel will all come to nought. But people imagine that they know about the nature of things, when they don't know about them, and, not having come to an understanding at first because they think that they know, they end, as might be expected, in contradicting one another and themselves. Just now I would hang this into every meeting room on this planet! A moment ago
  46. 46. 6 traits of math friendly programming language
  47. 47. #1 total functions
  48. 48. String => String
  49. 49. def toLowercase: String => String
  50. 50. def getUserById: String => String
  51. 51. // "3977e5a0-78..." -> "jay123" // "ill-formatted" -> null | Exception // "bc75ee93-bd..." -> null def getUserById: String => String
  52. 52. // "3977e5a0-78..." -> “jay123" // "ill-formatted" -> ~NOT POSSIBLE~ // "bc75ee93-bd..." -> null def getUserById: UUID => Try[Option[User]]
  53. 53. #2 type safety
  54. 54. UUID => Try[Option[User]]
  55. 55. #3 no side effects
  56. 56. #3 no side effects* *in 95% of your code
  57. 57. def setupSession(uuid: UUID): Unit
  58. 58. def makeSession(uuid: UUID): Try[Session]
  59. 59. #4 first class and higher order functions
  60. 60. // # 4.1 First class function List(1, 2, 3).map(x => x * 2) // List(2, 4, 6)
  61. 61. // # 4.2 Higher order functions def plus(a: Int, b: Int): Int = a + b def plus_(a: Int)(b: Int): Int = a + b def plus5: Int => Int = plus_(5) plus5(2) // = 7
  62. 62. #5 Parametric polymorphism
  63. 63. // # 5.1 Parametric polymorphism def dropFirstString: List[String] => List[String] def dropFirstInt: List[Int] => List[Int]
  64. 64. // # 5.1 Parametric polymorphism def dropFirst[S](items: List[S]) = items.tail
  65. 65. // # 5.1 Parametric polymorphism def min[S: Ordering](items: List[S]) = { val ordering = implicitly[Ordering[S]] items.min(ordering) }
  66. 66. // # 5.1 Parametric polymorphism type Ordering[T] = scala.math.Ordering[T]
  67. 67. // # 5.1 Parametric polymorphism def min[S: Ordering](items: List[S]) = { val ordering = implicitly[Ordering[S]] items.min(ordering) }
  68. 68. // # 5.1 Parametric polymorphism import cats.{Order, Reducible} def min2[C[_]: Reducible, S: Order](items: C[S]) = { val reducer = implicitly[Reducible[C]] reducer.minimum(items) }
  69. 69. // # 5.1 Parametric polymorphism import cats.implicits._ import cats.data._ min2(NonEmptyList.of(5, 2, 4)) // 2
  70. 70. #6 Type Inference
  71. 71. // Type inference // Local variable const x = 2 * 2 // number // Best common type const y = [0, 1, null]; // (number | null)[] // Context based window.onmousedown = mouseEvent => { // mouseEvent: MouseEvent console.log(mouseEvent.button); };
  72. 72. • Math is the most precise and unambiguously language that describes the world. • It’s the most advanced and rich language as well. • “Invest” in math friendly languages. • For Math = Correctness. • And that gives you confidence.
  73. 73. confidence is timeless
  74. 74. Inclusive and language-agnostic meetup group for those who cares about TypeSafety ~ welcomes new members and potential speakers ~ http://slack.typesafeutrecht.net http://meetup.typesafeutrecht.net
  75. 75. Q&A
  76. 76. REFERENCES • 1. «The Curry-Howard isomorphism for dummies» (INRIA Junior Seminar), 17/02/2015 https:// www.xn--pdrot-bsa.fr/publications.html • 2. IntelTeach Program: Designing Effective Projects, https://www.intel.com/content/dam/www/program/ education/us/en/documents/project-design/strategies/dep-question-socratic.pdf • 3.AllThe LanguagesTogether: https://thestrangeloop.com/2018/all-the-languages-together.html • 4.Type Systems,Wikipedia: https://en.wikipedia.org/wiki/Type_system • 5. How to implement type theory in an hour: http://math.andrej.com/2018/08/25/how-to-implement- type-theory-in-an-hour/ • 6. Comparison of programming paradigms,Wikipedia: https://en.wikipedia.org/wiki/ Comparison_of_programming_paradigms

×