1

In Chapter 23 of "Object Oriented Software Construction" (1988), Betrand Meyer makes a distinction between side effects, concrete side effects, and abstract side effects.

Meyer defines a side effect in the following quote:

A change performed by a function is known as a side effect to indicate that it is ancillary to the function’s official purpose of answering a query."

And he defines a concrete side effect in a definition box as:

A function produces a concrete side effect if its body contains any of the following: an assignment, assignment attempt or creation instruction whose target is an attribute, or a procedure call.

This distinction is hard for me to understand though, since I cannot think of an examples of functions which produce side effects but which do not produce concrete side effects. Meyer does not give us any either.

Would Meyer say that side effect and concrete side effect are synonymous? Or are there a class of side effects which are not concrete side effects?

(Note, the answer is not abstract side effects, since abstract side effects are themselves concrete side effects.)

  • Could it be a side effect that is not actually directly in the function called, but in a function called by that function? So function A is called. It calls function B and function B has a concrete side effect and function A is then sad to have a side effect, because it calls function B. – Jonathan van de Veen Apr 16 '15 at 6:31
  • Actually, that could be. Meyer points out that his definition of concrete side effect is "too weak" because it doesn't address calls to functions which produce side effects. He reasons that if we ban abstract side effects, then we're safe, and the nice part of his definition is that you only have to check the function body to see ifs concrete or not. Do you want to make your comment an answer? – Ceasar Bautista Apr 16 '15 at 14:24
7

Heating the processor and losing time by useless computations is a side effect which is generally ignored, so could be considered as not very concrete. It is not concrete according to the quoted definition of Meyer.

This is why compilers are permitted to optimize useless code like

 /// spend some time busy waiting in a useless computation
 for (int i=1; i<10000000; i++) 
    (void) log(5.0*i);

into an empty block.

This looks silly, but a lot of benchmark related questions are wrong because the compiler optimize code -by ignoring it-

BTW, at the lowest physical level, every computation has a thermal side effect.

So we always think in terms of some abstract machine, and we always ignore some uninteresting side effects (and care about some other side effects, notably interesting input or output). Sometimes you might even consider some debugging output as some ignored side effect. Some people are on the contrary very concerned about the energy consumption (e.g. for wearable devices) and they don't abstract that side effect.

  • 2
    Heating the processor ... is generally ignored. But not always: xkcd.com/1172. – hlovdal Apr 16 '15 at 8:00
  • I'd say it's less "we always ignore some uninteresting side effects" and more "some things aren't part of the language's semantics." Heating up the CPU is inevitable, but you can't write a program that can observe that effect. Likewise, the running time of 3 * 100 depends on the machine rather than the language: it's O(1) with hardware support for multiplication and O(n) without it (using iterated addition). And in any event, you can't observe the effect from the program. (You could ask the OS for the number of CPU cycles, but the request itself takes cycles...) That said, it still matters. – Doval Apr 16 '15 at 15:01
0

From the comments we discussed the following: it could be a side effect that is not actually directly in the function called, but in a function called by that function? So function A is called. It calls function B and function B has a concrete side effect and function A is then sad to have a side effect, because it calls function B.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.