Why callers should explicitly document storage classes
Vladimir Panteleev
vladimir at thecybershadow.net
Sun Aug 14 08:36:38 PDT 2011
On Sun, 14 Aug 2011 14:34:46 +0300, Mehrdad <wfunction at hotmail.com> wrote:
> 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?
I've raised this issue during voting for std.parallelism. I think the
consensus was that "lazy" before lazy arguments would be appropriate, but
"ref" would be mostly pointless, due to complex and reference types.
--
Best regards,
Vladimir mailto:vladimir at thecybershadow.net
More information about the Digitalmars-d
mailing list