4 ms·
I don’t see much difference between some_state.do_stuff() do_stuff(some_state)
by jshen 5y ago
I don’t see much difference between
some_state.do_stuff()
do_stuff(some_state)
- lolinder 5y agoThey're just different syntaxes for the same thing. I think what OP is driving at isn't the syntactic difference but making immutable what doesn't need to be mutable. You could do that with either syntax.
- jshen 5y agoYes, but I think the person he/she was replying to is right, the biggest problem is inheritance.
- rbanffy 5y agoThe second one scares me. It implies some_state is mutated (or not, we may just be logging something) by the do_stuff function while the first makes it very clear that some_state is in charge of doing stuff and that the implementation is aware of how some_state is implemented itself. OTOH, the second one would be much better (and imply immutability) if it were written as new_state = do_stuff(some_state) But it'd also allocate a new state.
- cowl 5y agoThis is a symtom of seeing everything with the OOP and state glasses. let's have do_stuff=square and some_state=2. What does square(2) imply?
- jshen 5y agoBetter yet, what does 2.square() imply.
- jshen 5y agoImmutability is independent of whether something is a method call vs a function call.