Re: Benefit of not defining the order of execution
- From: Flash Gordon <smap@xxxxxxxxxxxxxxxxx>
- Date: Wed, 18 Feb 2009 06:36:54 +0000
Richard Harter wrote:
On Tue, 17 Feb 2009 08:35:29 -0800, Keith Thompson
<kst-u@xxxxxxx> wrote:
nick_keighley_nospam@xxxxxxxxxxx writes:On 14 Feb, 04:51, Tim Rentsch <t...@xxxxxxxxxxxxxxxxxxx> wrote:[...]"Most programmers"? If that statement is based on actual data, that'sI know only that the person who wrote the code didn't think it wasor just didn't think. Most programmers assume left to right
important to force a particular order of evaluation.
evaluation and would be quite surprised if they were told they
were wrong.
interesting (and disappointing); if not, it would be good to see some
actual data.
I doubt that there is any such data. It sounds plausible,
though, because people read ordinary text left to right.
Presumably they also read code the same way, i.e., by default
they interpret it left to right. This could create the
unconscious assumption that the evaluation is left to right, even
if they know better.
But it's only plausible.
There are people who strongly believe that the arguments are evaluated right to left and pushed on to the stack as this is done. Thus when the function is called the left most argument is a fixed offset from the stack pointer making life simple for the compiler.
Sine different people assume different orders (and some know the order is unspecified as far as the language is concerned) forcing a specific order on compilers will certainly still leave people getting it wrong *and* will make some implementations less efficient. Seems like a loose-loose option to me.
(The context was a = f( g(x), h(y) );.)Now consider the case where the language specifies a left-to-rightthis is crazy! You claim that making the code more predictable
evaluation order. Let's look again at the example line. Now I have
to wonder if g() and h() interact;
makes the code harder to analyse!
If you assume a sufficiently competent programmer, you can assume
that g(x) and h(y) don't interact, because if they did then the
programmer wouldn't have written that statement. On the other hand,
"sufficiently competent" may approach "never makes mistakes".
On the other other hand, g(x) and h(y) *shouldn't* interact; if they
do, nailing down the order of evaluation makes the code well-defined,
but still poor style.
All of this depends upon the kind of analysis. If you are trying
to understand the operation of a piece of code, the default
assumption is that the author got it right. If you are trying to
debug it, the default assumption is that the author got it wrong.
When I'm analysing code for any reason my default assumption is that there will be a bug somewhere, after all no one is perfect!
--
Flash Gordon
.
- Follow-Ups:
- Re: Benefit of not defining the order of execution
- From: Kaz Kylheku
- Re: Benefit of not defining the order of execution
- From: Richard Harter
- Re: Benefit of not defining the order of execution
- References:
- Benefit of not defining the order of execution
- From: somenath
- Re: Benefit of not defining the order of execution
- From: Kaz Kylheku
- Re: Benefit of not defining the order of execution
- From: Tim Rentsch
- Re: Benefit of not defining the order of execution
- From: nick_keighley_nospam
- Re: Benefit of not defining the order of execution
- From: Keith Thompson
- Re: Benefit of not defining the order of execution
- From: Richard Harter
- Benefit of not defining the order of execution
- Prev by Date: Re: Logical operator not working in if condition
- Next by Date: Re: How often do you read the C standard?
- Previous by thread: Re: Benefit of not defining the order of execution
- Next by thread: Re: Benefit of not defining the order of execution
- Index(es):
Relevant Pages
|