Hacker News new | ask | show | jobs
by BeetleB 522 days ago
> People intuitively expect things to happen imperatively (and eagerly).

Eagerly? Yes. Imperatively? Not as much as SW devs tend to think.

When the teacher tells you to sort the papers alphabetically, he's communicating functionally, not imperatively.

When the teacher tells you to separate the list of papers by section, he's communicating functionally, not imperatively.

When he tells you to sum up the scores on all the exams, and partition by thresholds (90% and above is an A, 80% above and above is a B, etc), he's communicating functionally, not imperatively.

No one expects to be told to do it in a "for loop" style:

"Take a paper, add up the scores, and if it is more than 90%, put it in this pile. If it is between 80-90%, put it in this pile, ... Then go and do the same to the next paper."

People usually don't talk that way.

3 comments

Nope. The fact that he's telling you a high-level command is irrelevant. (If you didn't know what “sort the papers” means, he'd have to tell you in more detail; it's just the difference between calling your built-in sort routine or coding it.)

Anyway: He's telling you to do something, and you do it. It doesn't get more imperative than that.

You’re talking about what vs. how, but imperative vs. pure-functional is both about the how, not the what.

When you’re explaining someone how to sort physical objects, they will think in terms of “okay I’ll do x [a physical mutable state change] and then I’ll have achieved physical state y, and then I’ll do z (etc.)”.

Well, declaratively, not functionally. But point mostly stands