Not a side effect?
I was showing some code off to Sean last week and he looked at it and was rather upset. He claimed that it used a side effect to do its job and was bad programming. I promised to think about it and I did. I disagree.
The code was a method for use within a CFC that would handle all of the caching needed for the CFC. It would check if the CFC was cached under a specific name in a specific memory scope and if not, it would cache it. Basically a one stop shop caching.
It worked by passing a reference to the memory scope where the CFC was to be cached into the CFC method. As all structures are passed by reference, I could then alter the structure inside the CFC method without returning anything.
Now to understand the argument, I should define what a side effect is. Here's what Wikipedia says:
"In computer science, a function is said to produce a side-effect if it modifies some state other than its return value. For example, a function might modify a global or "static" variable, modify one of its arguments, write data to a display or file, or read some data from other side-effecting functions."Basically, a side effect is any operation that modifies some state other than its return value. Hm. So adding, editing or deleting data from a DB without returning any data or returning only a success value would be considered a side effect. Sending mail from a CFC is considered a side effect. There's a TON of CF stuff that would be considered a side effect so he must not be talking about that. Maybe he was talking about having a CFC alter a memory variable without returning a reference to that variable. That sounds likely.
Bottom line is that I learnt a new phrase, thought over my approach and have decided that a single method for caching that can be used in any CFC at any time is worth it. I'll have a writeup on my thinking up to the creation of the CFC and its code soon.
BTW, the act of storing a CFC in a memory variable is Cachine, not Persistance. If you disagree, argue with Sean about it here:
Persistence


I think "side effect" really means when you hide the fact that you are changing someone else's state, within the program you've written. Database and mail servers are not part of your program. A shared memory scope, however, is.