On Mon, Jul 15, 2013 at 4:02 PM, H. S. Teoh <span dir="ltr"><<a href="mailto:hsteoh@quickfur.ath.cx" target="_blank">hsteoh@quickfur.ath.cx</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Tue, Jul 16, 2013 at 12:52:21AM +0200, Joseph Rushton Wakeling wrote:<br>
> Hello all,<br>
><br>
> Quick query -- what's the preferred template variable name for a range type?<br>
><br>
> I've seen both R and Range used as options but want to confirm if there's a<br>
> preference for one or the other.  It occurs to me that Range might potentially<br>
> clash with some library or user-created entity.<br>
</div>[...]<br>
<br>
I don't think it matters in this case, as the name would only be visible<br>
within the scope of the template, and AFAICT would shadow any external<br>
definitions, so you shouldn't get into trouble with it.<br>
<br>
I generally use R 'cos it's less typing and I'm lazy, but Walter has<br>
been recently of the opinion that a more descriptive name is necessary<br>
for ddoc purposes, e.g., MyStruct(InputRange)(InputRange r) is much more<br>
self-documenting than MyStruct(R)(R r). Template signatures aren't<br>
included in ddoc output IIRC, so this can be an important consideration.<br>
<span class="HOEnZb"><font color="#888888"><br></font></span></blockquote><div><br></div><div>Using Range is vague (inputRange? etc) anyways so might as well use R. Including template constraints in generated doc would make this a non-issue.</div>
<div><br></div><div>I don't understand the rationale for not including them. I've raised the issue before, see [1].</div><div><br></div><div>For example in <a href="http://dlang.org/phobos/std_algorithm.html">http://dlang.org/phobos/std_algorithm.html</a> we have:</div>
<div><br></div><div>----</div><div><div>void reverse(Range)(Range r); </div><div><br></div><div>void reverse(Range)(Range r);</div></div><div><div>----</div><div></div></div><div>which is really not helpful.</div><div>It should show full signature:</div>
<div><div><br></div><div>----</div><div>void reverse(Range)(Range r) if (isBidirectionalRange!Range && !isRandomAccessRange!Range && hasSwappableElements!Range)</div></div><div><br></div><div><div>void reverse(Range)(Range r) if (isRandomAccessRange!Range && hasLength!Range)</div>
</div><div><div>----</div></div><div><br></div><div>and even better, with shorter type:</div><div><div><div>----</div><div>void reverse(R)(R r) if (isBidirectionalRange!R && !isRandomAccessRange!R && hasSwappableElements!R)</div>
</div><div><br></div><div>void reverse(R)(R r) if (isRandomAccessRange!R && hasLength!R)</div><div>----</div></div><div><br></div><div><br></div><div><br></div><div>[1]: implicit template constraint notation : <a href="http://forum.dlang.org/post/mailman.1006.1370836279.13711.digitalmars-d@puremagic.com">http://forum.dlang.org/post/mailman.1006.1370836279.13711.digitalmars-d@puremagic.com</a>). </div>
<div><br></div></div>