Re: [C++] Need help with program please

From: Alwyn (alwyn_at_blueyonder.co.uk)
Date: 01/31/05


Date: Mon, 31 Jan 2005 13:18:05 +0000

On Sun, 30 Jan 2005 22:32:43 -0800, James Dennett wrote:
>
> It's a bit of a mess, defining which operations are allowed
> and which are not, I'll openly admit. But not all effects
> are "side effects"; something done by a function whose only
> effect is to determine the return value isn't a side-effect.
> Effects other than those *are* side-effects. But we probably
> don't have language in the standard to formalize that.

The term 'side effect' is defined as an alteration is the state of the
system. Assignment to global variables and I/O are usually quoted as
typical examples. However, there's a point of view that says that _any_
destructive update is a side effect, even if it is to an automatically
allocated local variable. So:

int i;
i = 5;

is side-effecting, while:

const int i = 5;

is not, though the net effect of both is often the same, with or without
the 'const' keyword in the second example.

Personally, I can accept the current 'no side effects' rule for
'std::transform', though, from a practical point of view, it can appear
unduly restrictive, as long as it is made clear that 'std::for_each' can
modify sequence values through the iterators passed to it. This latter
seems to me to be the real anomaly.

Another anomaly would be that absence of side effects is required by the
standard without there being any means in the language to enforce such a
condition. You could introduce a keyword into the language for this
purpose, but even then, the compiler would not be able to verify in all
cases whether the programmer has kept his or her promise. Basically, this
is a mess which only pure functional languages are able to solve (perhaps
at some cost).

Alwyn



Relevant Pages

  • Re: [Lit.] Buffer overruns
    ... If we accept that integer representation in a language matters then we ... should have a proper way of dealing with it. ... integers and end up with an incoherent mess when all we needed in the ...
    (sci.crypt)
  • Re: Can Coco/R do multiple tokenizations
    ... to mess with other quasi-conventions, you might well mess with this.) ... what are some tokens following this or preceding this string. ... > In case of ambiguity I'ld idealy like to generate error and abort. ... at the language selection stage. ...
    (comp.compilers)
  • Re: Python from Wise Guys Viewpoint
    ... > The bad thing about such dark corners is: if you try to clean the mess ... > don't even try to mess with that code. ... > few maintenance cycles, produce a true mess, until the entire system ... > is thrown away and rewritten from scratch, in a different language, ...
    (comp.lang.python)
  • Re: Python from Wise Guys Viewpoint
    ... > The bad thing about such dark corners is: if you try to clean the mess ... > don't even try to mess with that code. ... > few maintenance cycles, produce a true mess, until the entire system ... > is thrown away and rewritten from scratch, in a different language, ...
    (comp.lang.lisp)
  • Re: A C++ VM? Has it beeen attempted?
    ... > Jeff Schwab wrote: ... >> Unless you wish not to be tied to Winblows. ... it's a mess. ... You blame the C++ language, which has twenty years of phenomenal ...
    (comp.lang.cpp)