Re: Operationalize orthogonality

From: Gene Wirchenko <genew_at_ucantrade.com.NOTHERE>
Date: Thu, 01 Jun 2006 11:31:27 -0700
Message-ID: <99cu721svjqqjshbhcm1o5797ajf2nvoel_at_4ax.com>


On Thu, 01 Jun 2006 13:52:26 GMT, Bob Badour <bbadour_at_pei.sympatico.ca> wrote:

[snip]

>LOL
[snipped funny example]

     I like the following one. It comes from a few posts in alt.folklore.computers (edited lightly):

My favorite is what I call the "Fives" program. With the correct declarations:

    A = 5;
    B = A;
    C = B;
    D = C;
    E = D;

would result in the value 101 in E! There are no overflows. At every step, the compiler is doing the thing that makes the most sense at that step, but the net result is silly. (This is not unique to PL/I, nor even to computers. People often do the same thing, reaching the wrong conclusion after a series of locally correct decisions.)

In this case:

    DECLARE A FIXED DECIMAL (5),

            B FIXED BINARY (5),
            C BIT (5),
            D CHARACTER (5),
            E FIXED DECIMAL (5);

A second poster:

The mistake made in the above program is in assuming that a string is a suitable receptacle for an arithmetic value. Converting the decimal value 5 to a bit string changes it completely -- you are looking at the binary digits that make up the number. 5 (base 10) = 101 (base 2). The final result -- 101 -- is correct in base 2.

The original poster:

You're missing the point.

Truncating a non-integer changes its value. At no step in my example does the value change.

It is true that, after several steps, the value has changed. But it is mighty hard to point to the one step where it happens.

You say "converting the decimal value 5 to a bit string changes it completely", but I didn't do that. I changed the decimal value 5 to a binary value 5, which is a perfectly reasonable thing to do. And then I change the binary value to a bit string, which also is a reasonable thing to do. C programmers do both operations all the time. As for "assuming that a string is a suitable receptacle for an arithmetic value", have you never heard of printf (or sprintf)? How else do you communicate the result of your calculations to a human?

> The final result -- 101 -- is correct in base 2.

Except that the final value isn't declared binary. It's declared decimal.

Sincerely,

Gene Wirchenko Received on Thu Jun 01 2006 - 20:31:27 CEST

Original text of this message