Code Factorization: How to Organize Boilerplate Code
summary
Claim: extracting three parameters (collection, step function, initial) into a Loop higher-order function replaces repeated iteration in sum and evens and visibly reduces cognitive load. Implementation details include parameterizing case dispatch as tuples of predicate/action, composing small functions with pipe, using identity function as a default, and currying to produce lift/map variants. Demos show the refactors compile to simpler code and clarify intent; deeper mentions include Y combinator, functor, monad, and optics as next steps.
AI-written summary · about
chapters (17)
- 0:00Code factorization intro
- 1:24Boilerplate code overview
- 3:36Cognitive load and readability
- 6:10Five paradigms to remove boilerplate
- 6:53Limitations of object-oriented programming
- 7:57FP as solution
- 9:01Higher-order functions in practice
- 10:50Abstracting case inspections
- 13:29Boilerplate in constant calculations
- 15:20Function composition with pipe
- 18:25Identity function power
- 21:29Identity for abstraction
- 23:24Currying and multi-angle views
- 26:47Lifting functions
- 27:11Advanced FP concepts
- 29:46FP benefits summary
- 30:56Choosing the right paradigm
related talks
47mPrinciples of Clean Functional Programming
52mHigher Order Functions for ordinary developers
12mWhy Less Code Isn’t Always Better
56mBack to Basics: Functional Programming and Monads in C++
28mExplicit Elixir
32mFive Lines of Code
36mRefactoring Elixir - Lessons Learned from a Year on
29mSaga of a Single Function by Edgar Marukyan (Eng) | JSConfAM19
