3 ms·
I feel the same way. As hobbies I like to work with my hands on things like carpentry and metalworking. OOP maps pretty well to how I think about accomplishing
by ryandrake 7y ago
I feel the same way. As hobbies I like to work with my hands on things like carpentry and metalworking. OOP maps pretty well to how I think about accomplishing step by step tasks on physical objects:
Step 1: Use this tool (instance of a class) to perform that modification (call a mutating method) to affect this workpiece (another class instance). Step 2: Now use that tool...
So if I’m building a cabinet, my mind plans out something like:
saw.cut(wood1);
saw.cut(wood2);
wood3 = glue_bottle.apply(wood1,wood2);
sander.sand(wood3);
Etc.
I’ve always thought of a program as just a more elaborate series of step by step commands. Computer do this to this thing, now do that to that thing (which may, through a subroutine, mean doing other nested tasks). I can’t wrap my mind around accomplishing a step by step process with functional programming. Just haven’t made that mental leap yet, probably because I’m so used to thinking the other way.
- dragonwriter 7y agoFor a simple case like this with no diamond-shaped dependencies, the direct functional expression is inside-out rather than top-to-bottom: sand( sander, glue(bottle, cut(saw, wood1), cut(saw, wood2)))
- username90 7y agoNow write that code with tools having durability. In OOP that is trivial and require no code changes elsewhere.
- madhadron 7y ago> I’ve always thought of a program as just a more elaborate series of step by step commands...Just haven’t made that mental leap yet, probably because I’m so used to thinking the other way. Yes, it's a hard mental leap the first few times. And there's another leap to logic programming that is almost as large as the jump to functional programming. Perhaps a physics analogy would be useful. A physicist may use a local, kinematic view: the object is here and has this velocity, and this force on it, so in a fraction of an instant that will make it move this much, and in another fraction of an instant it will move this much more... A physicist may also use a global view: if I consider the set of all possible paths that start at point A and end at point B, what distinguishes the one an object will actually take? Both are useful, and things that are obvious in one are usually quite obscure in the other.