A light introduction to the equivalent models of Alan Turing and Alonzo Church. These serve as a metaphor for procedural and functional oriented programming. Disadvantages of the procedural and advantages of functional programming are presented, with some speculation about the opportunity to bring more women into technology.
3. Early 20th Century Computers
Entscheidungsproblem
The Halting Problem asks “When can
we send these people home?”
Alan Turing: Idunno
4. What is this Turing Machine we speak of?
The diagram at right shows different
formal models of automata, or logic
machines.
Each inner layer is simpler and more
understandable.
Outer ones are more powerful.
5. Was this Turing’s Inspiration
The first application of punched cards was in looms like
this one shown here.
The cards allow the machine to control the threads to
make elaborate, repeatable patterns in the fabric.
6. The von Neumann Architecture
By the time WW2 ended,
mathematician John von
Neumann proposed this
architecture for computer
hardware.
This is what most
computers use today.
7. BASIC Procedural Code
This convinced me to reject Computers & become a Mathematician.
10 X = 5
20 X = X + 4
30 PRINT X
It follows a procedure: this, then do that, then keep on until done
8. Billionaire 101
While I was sticking my nose up at
BASIC, a kid dropped out of Harvard to
punch holes this strip of paper tape.
Whereas I used the chads to pull pranks
on fellow students.
Bill Gates started Microsoft
This is Microsoft BASIC
9. The Limits of Bill Gates’ Microsoft
“The Software Crisis”
Code Reuse Is Hard
Testing/Debugging Is Hard
Concurrency and Asynchrony Is Hard
Extreme Perseverance Disorder (Only Autistic Savants Need Apply)
10. Procedural vs. Functional Programming
How vs. What
N = N + 1 is really bad algebra. Do I
subtract N from both sides?
We need total awareness of every thing
the code might do.
vs tools translating “what” into “how”
11. Lambda Calculus
...a formal system in mathematical logic for expressing
computation based on function abstraction and application
using variable binding and substitution. It is a universal model
of computation that can be used to simulate any Turing
machine.
-- Wikipedia
12. Manage 6 CPU Cores & use the Internet
Suppose, we seek to efficiently program
a 6-core Apple iPhone X. And keep all
those cores busy.
...and go to the web to access data with
varying latency.
Procedural programming just doesn’t
cut it.
13. Actionable λ-Calculus
Let’s start with sin
sin = angle => opposite / hypotenuse
Note: no side effects
Note: memoization == “CRC Handbook
of Mathematical Tables”
14. Every λ can be a function of One Argument
IsEqual = (x, y) => (x === y)
IsFour = (y) => IsEqual(4, y)
CurryiedIsEqual = x => y => (x === y)
Functions can return functions.
Haskell Curry: an N-argument function made from 1-argument functions that each
return a function
15. Functional Programming Advantages
Pure functions are easier to test
No side effects mean fewer “Chesterton fences” => easier refactoring
“What was the earlier programmer thinking?”
Immutable data mean no need for concurrency locking
Parallelized, asynchronous execution
Mathematical reasoning about code
16. Functional (map/reduce) Sandwitch
We need only write and test
two functions:
● Slice
● Stack
It’s troublesome to slice/stack
different things, but each
difference can be tested in
isolation.
17. Algebraic Data Types
Algebra is more than just the stuff we did in High
School. It also governs phenomena like Rubik's
cubes or quarks.
Capture domain semantics in Algebraic Data Types
(Joins and Unions)
Algebraic Data Types (in functional type systems)
enable TypeScript/Haskell/F# compilers to catch
more errors.
18. Conflict-Free Replicated Data Types
Suppose a blockchain
node is temporarily
disconnected...
Idempotent functions
f(x) = f(f(x)) = f(f(f(x))) …
19. Stuff I’m Not Talking About
“A monad is just a monoid on the category of endofunctors.”
Functional programming introduces side-effects in a controlled, mathy way. These
arcane terms scare pointy-haired bosses and negotiate fat raises:
● Monoids,
● Functors,
● Monads,
● Applicatives
20. Trigger Warning
Speculation follows about a biological difference between XX-chromosomed
people and XY-chromosomed people. This is mere speculation. I welcome
experimental confirmation or refutation. Feel free to disagree.
21. Sex, Turing and Church
Some Boys seem more “spatially” oriented
Some Girls seem more “grammatically” oriented
Procedural Programming requires near-autistic perseverative obsessiveness
about every detail all over everything, hence male dominance in procedural
programming
Functional Programming requires a more linguistic/verbal approach to
programming, hence an opportunity for female involvement
22. Needed: Women in STEM
The Functional Programming paradigm may be a better fit for the female mind.
We need everyone leveraging their skills as best fitted.
Hence, getting females into STEM, and Functional Programming has come at a
great moment.
We should encourage all XY-chromosomed people with an inclination toward
technology to start learning Functional Programming
Notes de l'éditeur
The Hilbert question #2 led to the Halting Problem. In 1937 Alan Turing published On Computable Numbers, with an Application to the Entscheidungsproblem. His answer to the Halting Problem: Idunno.
I always preferred it when I could pose a question as a finite-state machine. I think the coolest thing I’ve seen of late is something called Reactive systems where we have nice, provably correct Functional sub-system components interacting with each other in a strictly regulated way as a state machine.
My daughter wants me to help her with a little project to make a loom. I don’t think it will be as elaborate as this.
For years I refused to admit that I knew how to program in BASIC.
This is all abstract and mathematical. And there’s a reason why it has not been adopted by working software developers. Even if I understood this theory, how can I make this information actionable?
This drove a lot of philosophy of mathematics in the middle of the 20th century onward. This is still fairly abstract, but it is foundational. It provides a basis for reasoning about code, because it has mathematical rigor. This allows us to mathematically prove code is correct.
Idempotent is mathy jargon for simple stuff like adding zero, or multiplying by one. It’s virtually impossible to consider all the contingencies of bad timing, communications interruption, and Murphy’s Law when you update data on all the database nodes. Thus you make update functions idempotent.