any news on const/invariant?

Bill Baxter dnewsgroup at billbaxter.com
Wed Nov 28 11:54:36 PST 2007


Christopher Wright wrote:
> Janice Caron wrote:
>> A thought occurs to me. (And it's a good one). 
> 
> I think so, too. It'd help whenever I have a hairy method with lots of 
> locals that I was having trouble keeping track of.
> 
> There's a small problem of scope, but that's manageable:
> 
> // var1 should be const starting here...
> const(var1) {
>    ...
>    // var2 should be const starting here...
>    const(var2) {
>       ...
>    // make var1 non-const now
>    }
> }
> const(var2) {
>    ...
>    // mave var2 non-const now
> }
> 
> Of course, maintaining a large method with several of these const 
> windows might be a bit troublesome. But it replaces some hard-to-find 
> bugs with some easy-to-find ones.

I suspect you'd also be able to do something along the lines of:
{
   const(var1):  const(var2):
   ...

}// end var1,var2 constness

Anyway, the same kind of scoping mess exists now with 'with'.
I've long wanted a 'with(var1):' form of it.

--bb



More information about the Digitalmars-d mailing list