Re: [S] unusual result

Duncan Murdoch (dmurdoch@pair.com)
Thu, 26 Mar 1998 18:40:32 GMT


>I can't help giving my opinion on this issue.

Since everyone else is, I will too:

I think anyone who writes an expression whose value depends on the
order of evaluation deserves any bugs it introduces into their
programs.

I don't know if the documentation for S-PLUS states anywhere whether
there are guarantees for the order of evaluation of the terms in a
complex expression. If it does, and these examples don't follow it,
then there's a bug. But the solution to the bug is to change the
documentation. Having a language guarantee a particular order of
evaluation is a Bad Thing.

(I'm not talking about operator precedence here; that's obviously
good. I mean things like the order in which a and b are evaluated in
the expression "a + b".)

The reason it's bad is that it will surely introduce bugs into the
program you or your colleague writes next week (or next year), when
you import the code from the current program into a project in a
language that follows different rules.

If you have an expression "a + b", and you want to be sure that a is
evaluated before b, then you should force it, by storing the value in
a temporary variable in a separate statement that comes before the
addition, e.g.

temp <- a
temp + b

That's unambiguous in any language.

That's my opinion, anyways...

Duncan Murdoch
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news