any news on const/invariant?

Christopher Wright dhasenan at gmail.com
Wed Nov 28 11:51:34 PST 2007


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.



More information about the Digitalmars-d mailing list