3 ms·
As they say, closures are the poor man's objects and vis versa. That said, most usage of closures in practice tend to have very little state manipulation -- a
by xmcqdpt2 3y ago
As they say, closures are the poor man's objects and vis versa.
That said, most usage of closures in practice tend to have very little state manipulation -- a closure with 5 mutable fields is weird, an object with 5 mutable fields is "clean code" approved. Also, closures have only one entry point which makes making complex ones much more difficult (you have to implement a state machine or dispatch or whatever.)
Standard "design patterns" over-the-top OOP translated to FP would be like passing around collection of closures (one per method) that all alter a big shared mutable state. At that point OOP is definitely going to be faster, but the FP code would be so ugly you wouldn't write it like that to start with.