Reading or writing in a stream makes a mark move along to show where the most recent read or write occurred. (That’s a side effect!) Writing to a screen leaves an irreparable mark on it—a long lasting side effect—and writing to paper is even more indelible—yet another long term side effect. Requiring a user to type on a keyboard is likewise irreversible. In short, side effects are unfortunately omnipresent in computing… Of course, it is possible to imagine living in an ideal world with no side effects, but we would suffer from a kind of computer-autism there since we would not be able to communicate the results of computations.
—Christian Queinnec, Lisp in Small Pieces
I read the above on the toilet this morning (experiencing some very sub-ideal side effects of certain decisions made last night) and, after the usual eye rolls, it occurred to me that the term “side effects” to describe any observable effect on the world is actually perfect.
“Side effects” are how we make programs make themselves known. They are how we know our programs do something. In other words, if a program has no side effects, it’s impossible to know if it runs at all, and if it’s impossible to know if the program runs at all, why write it? In still other words, we write programs for their side effects. We want the side effects. The “side effects” are the whole point. No user ever ran an ls -la
, saw nothing appear on screen, and thought “this is truly the best of all possible worlds.”
Somehow, “side effects” in the positive sense of “making a difference in the world” became conflated with the negative sense of “all this global state and stuff that has made my program a flying spaghetti monster”. The positive sense means you’ve done your duty. The negative means you’ve made a mess. “Side effects” are suspect on the level of functions, and are less than ideal for unit tests, but on the level of programs they’re crucial, existential.
So, to distinguish between these two senses, I propose the term “entanglement” for the negative sense, and that we keep the term “side effects” for the positive sense, the sense meaning “why we bother to write programs at all”, because that’s programmer humor at its finest.