Transitive const sucks

Walter Bright newshound1 at digitalmars.com
Wed Sep 12 11:55:58 PDT 2007


Janice Caron wrote:
> Even something as simple as this needs logical const
> 
> class MyMathClass
> {
>     invariant int multiply(int x, int y) /* logically const */
>     {
>         debug logfile.writeLine("multiply.called");
>         return x * y;
>     }
> 
>     debug private Stream logfile;
> }
> 
> You can't tell me that's not a real world need.

You can:

1. make logfile a static member.

2. not use invariant on the multiply. After all, if it isn't actually 
invariant, the invariant declaration wouldn't have any more meaning than 
the comment you put on it.



More information about the Digitalmars-d mailing list