Comment by zzzcpan
10 years ago
They are not exactly equivalent though. It is not possible to completely abstract away state changes with objects. You always end up with at least two calls that you have to keep track of.
10 years ago
They are not exactly equivalent though. It is not possible to completely abstract away state changes with objects. You always end up with at least two calls that you have to keep track of.
I'm not sure that I would agree here. Do you have a simple example?
vs
EDIT2: exact behavior is not the point, keeping track of things is.
That doesn't seem to have anything to do with objects versus closures. In both cases the right answers is absolutely to pass a function to DoSomething be it a function or a method.
If you're considering a language deficient of functions then we can take advantage exactly of the idea that objects can embed functions by having a "callable" thing.
1 reply →
Classes don't need to have mutable state. I've written several rather useful classes that were completely immutable after initialization. As such, there are no things to keep track of. No side-effects, nothing like that, a snapshot in time of whatever values I need to pass elsewhere.
Pass an object to DoSomething and you get the same thing as the closure.
1 reply →