(Strongly Typed) Functional Programming:
A Superior Paradigm?
Two Paradigms
Imperative
- abstracted from the hardware
Functional
- build on abstract math
Functional: A Continuum
Language
Functional
Type system
JavaScript
Somewhat
What's a type?
C#
Somewhat
Some safety
Clojure
Impure
Weak
F#
Impure
Algebraic types!
Haskell
Pure
No null/subtypes
Idris
Pure
Dependent types
Lowest Common Denominator
Functions as first-class values
and so, higher-order functions
Closures
But to really be functional...
First-class syntax for functions
First-class semantics for functions
The primacy of immutability
Functional Purity
No (implicit) effects
Algebra of types
Pure models of an impure world
So, the Big Question
™
Not black and white
Not fanboyism
You want to write VB6?
There are pros and cons, but...
Overall C > Assembly
Overall C# > C
Overall F# > C#
Cons of functional programming
Steep learning curve
Too academic?
Effects are awkward in pure FP
Take Courage
Ongoing learning is not optional
Learn an impure language first
Valuable things cost more
Why do we disdain academics?
Engineers don't disdain physics
Effects may be awkward, but...
Much active R&D on this
You don't need effects as often as you think
You can reap many benefits without being purist
Easy wins in FP
Immutability
Concurrency much simpler
Statelessness
The Simplicity of FP
Less semantic clutter
Less mental clutter
Less syntactic clutter
The Clarity of FP
Obvious correctness
vs
Expressive Power of FP
Types are not only for error prevention
Types model the domain
Comments < Tests < Types
Does FP enable Agility?
Compiler gives more feedback, sooner
Types can prevent stupid errors
Testing versus formal verification
I can't just
tell
you how good it is
So, no more OOP at all?
Idea #1: Mix & Match
Impure languages are practical
Mixing limits the benefits of FP
Choose your tradeoffs
Idea #2: OO outside, FP inside
OOP is good at modeling processes & state
FP is good at modeling the domain
OO architecture, FP code
Objects = microservices
Unmixed but inclusive
Methods = messages
My Conclusion
Functional programming is a superior paradigm to imperative
Choosing your tool is an exercise in trade-offs
What do you think?
Made with Slides.com