Naming convention for template parameters

monarch_dodra monarchdodra at gmail.com
Tue Jul 16 02:05:58 PDT 2013


On Monday, 15 July 2013 at 23:09:59 UTC, Joseph Rushton Wakeling 
wrote:
> On 07/16/2013 01:02 AM, H. S. Teoh wrote:
>> I generally use R 'cos it's less typing and I'm lazy
>
> ... ditto ... :-)
>
>> but Walter has been recently of the opinion that a more 
>> descriptive name
>> is necessary for ddoc purposes, e.g., 
>> MyStruct(InputRange)(InputRange r)
>> is much more self-documenting than MyStruct(R)(R r).
>
> Yes, that was my main consideration for this case.  I'm worried 
> about the
> potential for clashes with other elements of the namespace, 
> though.
>
> I'm thinking in particular of the tendency to use Random as the 
> template
> parameter name for a random number generator, when Random is 
> actually an alias
> for the default RNG type.  I've proposed a blanket rewrite of 
> such template
> parameter names to Rng: 
> http://d.puremagic.com/issues/show_bug.cgi?id=10434
>
> Particular context is that I'm trying to tidy up/standardize 
> some bits of
> std.random and I'd like my standards to be future-proof. :-)

struct SomeRangeWrapper(Range)
{
     alias R = Range;
     //...
}

Fixed.

I think "Range" is better, because it shows up in the docs, and 
is a bit clearer than "R" (although anybody doing D should 
understand it). But when working, "R" is easier. The above 
approach solves both.


More information about the Digitalmars-d-learn mailing list