Timeline for OO vs FP: What is a good approach to understanding if heavy wrapper classes should be used?
Current License: CC BY-SA 4.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 1, 2023 at 3:35 | comment | added | Alexander | For a sufficiently sophisticated optimizer, it won't matter. (single method) objects and closures are pretty much the same thing at an implementation level: a chunk of memory to capture state, and a pointer to a function that implements behaviour. Optimizing function currying is pretty much the same as devirtualization (replacing dynamic dispatch with static dispatch in cases where the receiver can be discovered statically). In both cases you would just end up with function calls that mutate state, which could even be inlined completely. | |
Aug 31, 2023 at 13:21 | comment | added | panlex | Well here is another way to think about it. What nifty syntax tricks feed into compiler optimizations? For example chaining operations instead of performing each in isolated for-loops. While we are looking at Python many of my questions come from past Scala projects which internally called Java APIs requiring similar transformations. I made it work but it didn't feel like I reached a conclusion on this issue of encapsulated self-transformation vs externalization transforms which can be applied to other objects as they are developed. | |
Aug 28, 2023 at 18:47 | comment | added | Alexander | Could you elaborate on what exactly you mean by "a strictly functional object to achieve the same effect"? Are you referring to the curried function that I described? Assuming so, my answer would be "I would do as the Romans do." It would be really weird to model this computation using currying in a language like Java or Python, where that isn't the norm. | |
Aug 28, 2023 at 13:50 | comment | added | panlex | @Alexander hmm that makes sense. So I'm curious, do you have guidelines that you follow to decide between encapsulating capability in a class, vs. building a strictly functional object to achieve the same effect? | |
Aug 26, 2023 at 17:16 | comment | added | Alexander |
The "FP approach" wouldn't just be to define a function that does the transformation that callers are expected to always remember to call. It would be to take that function, curry it with the get_object_positions , and return a new function that does the combination of getting positions and transforming them. In effect, this is exactly identical to your "heavy wrapper class". It's an object that does both.
|
|
Aug 26, 2023 at 11:10 | review | Close votes | |||
Sep 2, 2023 at 3:06 | |||||
Aug 26, 2023 at 7:56 | answer | added | Doc Brown | timeline score: 2 | |
Aug 26, 2023 at 6:53 | history | asked | panlex | CC BY-SA 4.0 |