Const unbackled

Georg Wrede georg at nospam.org
Mon Mar 24 19:09:48 PDT 2008


I might have a function to test some property of a value. I expect to 
usually need this function inside some other functions.

Since I know this function does not change its input data, I now want to 
_advertise_ this fact, according to the prevailing /mode du jour/.

Let's say my function validates a string or a stream of UTF for internal 
correctness. In stand-alone usage it would look like

     vutf(s);  // validate string or stream s, and throw if bad
     S sf = translateToFinnish(removeWhitespace(s));

But usually I'd use it inside something else, like

     S sf = translateToFinnish(removeWhitespace(vutf(s)));

In the first case I discarded the output of vutf but want to be sure 
that s stays the same, in the second case I used it as input to the 
enclosing function. Since vutf does not modify its input, I should 
somehow be able to advertise this fact.

I admit this example is contrived, but you get the idea.


We should stop discussing whether/how this is implementable 
syntactically/semantically, and instead start discussing USE CASES, and 
DO WE NEED THIS IN THE FIRST PLACE.

(One might also ponder on whether making deeply nested function calls in 
assignments is desirable in the first place.)

UNLESS we think this out BEFORE ending up on a consensus on 
syntax/semantics, we might end up with what the C++ folks did with 
multiple inheritance. (They were too busy figuring out how to implement 
it, instead of whether there's any real-world use for it or whether it 
is implementable at all in a practical and usable way.)

Use cases mentioned in the relevant NG discussions are checking for 
properties, returning slices, what else? Where is this indispensable?



More information about the Digitalmars-d mailing list