CS 251 Fall 2019 Principles of Programming Languages
Ben Wood
λ
CS 251 Fall 2019
Principles of Programming Languages
Ben Wood
λ
https://cs.wellesley.edu/~cs251/f19/
FP vs. OOP Problem Decomposition
1 FP vs. OO Problem Decomposition
Two world views
FP FP: fu functions s perform so some operation OOP OOP: cl classes/prototypes give beha havi vior to some kind of data Which is better? Depends on software evolution, taste.
Each can (awkwardly) emulate the other.
2 FP vs. OO Problem Decomposition
Common pattern: expressions
3
eval toString usesX … VarX Sine Times …
Variants of a type of data Operations over type of data
FP vs. OO Problem Decomposition
FP: behavior by operation
4
eval toString usesX … VarX Sine Times …
Datatype with constructor per variant Function per operation with branch per variant
Pattern-matching selects variant. Wildcard can merge rows in a function.
FP vs. OO Problem Decomposition