OO Side Effect Free Programming
programmersparadox.com
OO Side Effect Free Programming
1–8 of 8 posts
Re: OO Side Effect Free Programming
#2Edit: It occurred to me that there is a case when you need to move state out of the stack to global or instance variables: programming async IO. It is notoriously inconvenient for exactly this reason.
Re: OO Side Effect Free Programming
#3Re: OO Side Effect Free Programming
#4I disagree. Obsessiveness with small methods means less opportunity to keep your transient state in local variables, meaning you are going to make it object state (use object fields), which would actually increase your side effects. Edit: It occurred to me that there is a case when you need to move state out of the stack to global or instance variables: programming async IO. It is notoriously inconvenient for exactly…
Re: OO Side Effect Free Programming
#5I disagree. Obsessiveness with small methods means less opportunity to keep your transient state in local variables, meaning you are going to make it object state (use object fields), which would actually increase your side effects. Edit: It occurred to me that there is a case when you need to move state out of the stack to global or instance variables: programming async IO. It is notoriously inconvenient for exactly…
Method arguments are a decent place to keep transient data as well. Local variables and object fields are not the only options for scoping your data.
Re: OO Side Effect Free Programming
#6I disagree. Obsessiveness with small methods means less opportunity to keep your transient state in local variables, meaning you are going to make it object state (use object fields), which would actually increase your side effects. Edit: It occurred to me that there is a case when you need to move state out of the stack to global or instance variables: programming async IO. It is notoriously inconvenient for exactly…
Method arguments are a decent place to keep transient data as well. Local variables and object fields are not the only options for scoping your data.
Re: OO Side Effect Free Programming
#7Re: OO Side Effect Free Programming
#8No, you can still have side effect free programming in OO. All of the techniques for programming without using mutable state are language agnostic and should carry over to whatever OO language you are using. You might have problems in languages that lack tail-call optimization, but even that can usually be worked around by using folds.
Now, I'm not claiming that it's feasible to make an entire app in (for instance) Java purely functional, but you can definitely build the majority of your app/library/whatever without using mutable state.