|
|
|
|
|
by hcarvalhoalves
4819 days ago
|
|
Ideally, we would all write programs by assembling declarations, imperative code would be limited to internal implementations. That's largely the reason it's good practice to abstract away implementation behind APIs - what you have left is almost a pure declarative language, or DSL, that maps 1:1 your problem domain, without looping or branching or I/O (which are computation details). Taking the example from the original article, it would be more akin to: // Implementation
function double(n) {
return n * 2;
}
// Declaration
[1,2,3,4,5].map(double)
=> [2,4,6,8,10]
|
|
Of course, in the cooking methaphor, I'm ok with mutating elements and just doing:
This clearly has issues if multiple "cooks" are working with elements. But is ridiculously easy to intuit regardless. (Precisely because in real life so many things are changed by imperative commands.)