Invariants are useless the way they are defined

Ali Çehreli acehreli at yahoo.com
Sun Aug 25 23:14:01 PDT 2013


On 08/25/2013 05:16 AM, deadalnix wrote:

 > The problem is that invariant are checked at the beginning/end on public
 > function calls. As a consequence, it is impossible to use any public
 > method in an invariant.

That's a very interesting observation. Could the solution be running the 
invariant only once, at the outermost public function call? Hm... It 
would have to be a runtime feature then, right? Every public function 
would have calls to the invariant but those calls would have to be 
elided at runtime. I think...

Here is another interesting observation: It is acceptable and quite 
normal that the object is in limbo state during a public member 
function. As a consequence, any function that operates on the object 
must use the object in a write-only fashion during that time frame. This 
is true even for non-member functions that the object is passed to. So, 
in theory, even a logging function cannot use the object. Hm...

I jokingly propose a new function parameter attribute: 'static out', 
meaning write-only. ('out' already has a conflicting meaning and 
'static' is not overloaded enough yet. :p)

Ali



More information about the Digitalmars-d mailing list