Hidden argument kind antipattern

bearophile bearophileHUGS at lycos.com
Tue Apr 19 16:43:50 PDT 2011


dsimcha:

>  I did it because it seemed like things like this were kind of the point of lazy
> parameters.

I agree. In my opinion the problem is not you using in your module a language feature designed for that very purpose. What's in question is the syntax of that language feature. I don't mind lazy arguments, but it can be argued that's better for them to require a "lazy" prefix at the calling point too. This little syntax problem that was already raised during the D2 design phase.

Two little disadvantages of requiring "lazy" prefix at the calling point too are:
- A little more code to write. This is not really a typing problem of five extra lowercase chars (there is a space too), but a problem of succinctness and syntax noise. I think being it lower case the added syntax noise is not so high.
- It's less general code. Changing a normal argument from lazy to not lazy or from not lazy to lazy becomes not transparent any more, it requires changes at all call points. Recent versions of C# have softened the requirements of the "ref" annotation at the calling point, when using COM:
http://en.wikipedia.org/wiki/C_Sharp_4.0#Optional_ref_Keyword_when_using_COM

I am undecided still. I weakly agree to require "lazy" suffix at the calling point too.

Bye,
bearophile


More information about the Digitalmars-d mailing list