Why callers should explicitly document storage classes

Mehrdad wfunction at hotmail.com
Sun Aug 14 04:34:46 PDT 2011


Consider this example:

     // In module foo.d:
     void baz(bool condition, lazy int value)
     {
         if (condition)
             writeln(value);
     }

     // In module bar.d:
     import foo;
     bool someCondition() { return false; }
     void main()
     {
         auto vals = [1, 2, 3, 4];
         while (!vals.empty)
             baz(someCondition(), items.moveFront());
     }

There is **absolutely NO WAY** to figure out what's wrong at the calling 
site. You need to check /every/ method call and make sure nothing weird 
is happening (e.g. lazy), and it's pretty much impossible to figure it 
out unless you're intimately familiar with the entire library you're 
calling -- something which (obviously) doesn't scale.

I don't know of a similar example off the top of my head for out/ref, 
but the same idea applies.

Is this convincing enough that we need to document storage classes at 
the CALLING site, rather than just the CALLEE site?


More information about the Digitalmars-d mailing list