Hacker News new | ask | show | jobs
by plafl 3661 days ago
I have a cup of coffee, if I drink a little I don't think a new cup of coffee with less coffee has been created, just that the old one is different. There are some times where imperative thinking seems more natural.
4 comments

I guess that applies to most programming paradigms. Their metaphors rapidly break down if you want them too.

I also don't send a message to the cup of coffee to reduce the amount of liquid that is in it and pass it a PourIntoMouthStrategy object to act on.

> There are some times where imperative thinking seems more natural

This is certainly true. But there are also times when there is nothing natural about it at all. Consider this scenario:

I give you a cup of coffee. You set it on your desk to cool. Then when you go to take a sip, the cup is empty! You see, I gave you the same cup I was drinking from.

A race condition I guess. At least we didn't try to drink at the same time.

For the record I usually write functional code. Let me put another example instead of coffee. If I have a differential equation, "dx/dt=f(x,t)", I think of the solution as a function "x(t)", but if I try to solve it numerically or even try to reason about it I visualize how "x" changes with time. Is this the reason why numerical code is usually imperative? Maybe it's just because of performance but I really think that sometimes there is a cognitive burden trying to reason fully functionally (I can visualize the parabolic trajectory of a ball but I cannot visualize the 6-dimensional trajectory of an airplane doing a manouver without seeing it "change with time").

I see your point. Learning how to reason effectively in higher and higher levels of abstraction can be daunting; however, it can pay off very well. Ask a mathematician about the set of interesting problems that can be visualized and they will tell you it has measure zero.
I think in a block-time model of the world. The coffee cup now and the coffee cup a minute ago are different things; my memory of the coffee cup a minute ago doesn't suddenly have less coffee in it.