<br><br><div class="gmail_quote">On 26 August 2012 16:43, Johannes Pfau <span dir="ltr"><<a href="mailto:nospam@example.com" target="_blank">nospam@example.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Am Sun, 26 Aug 2012 13:19:35 +0300<br>
schrieb Manu <<a href="mailto:turkeyman@gmail.com">turkeyman@gmail.com</a>>:<br>
<div class="im"><br>
> Looks good, though one thing annoys me as always throughout the D<br>
> docs, liberal use of auto can make them very difficult to understand.<br>
><br>
> auto result = hash.finish();<br>
><br>
> >From the examples where this appears, I have absolutely no idea what<br>
> 'result' could possibly be and what I can do with it, and you're<br>
> forcing me to go and dig further for that information (waste of time).<br>
> Surely there would be no harm in just writing the type there for<br>
> clarity?<br>
><br>
> <rant><br>
> I'd personally like to see auto abolished, or at least heavily<br>
> discouraged for the sake of clarity from code examples throughout the<br>
> docs. I'm constantly having to chase up what auto's may resolve to<br>
> when reading examples >_<<br>
> You may argue this demonstrated un-idiomatic code, and my trouble is<br>
> due to inexperience; I ask, who is most likely to be reading docs?<br>
><br>
<br>
</div>OK, I'll fix this if std.digest is accepted into phobos.<br>
<br>
However, in this example auto is not just used for convenience, it has<br>
an actual use case:<br>
<br>
As documented here<br>
<a href="http://dl.dropbox.com/u/24218791/d/phobos/std_digest_digest.html#ExampleDigest" target="_blank">http://dl.dropbox.com/u/24218791/d/phobos/std_digest_digest.html#ExampleDigest</a><br>
(finish method) the type returned by finish can differ between different<br>
hash implementations. It's always a static array of ubyte, but for crc<br>
it's ubyte[4] for sha1 it's ubyte[20] and for md5 it's ubyte[16]. So<br>
in templated methods, auto is more generic than hardcoding a type. The<br>
equivalent to auto is using digestType!Digest, so<br>
<br>
auto result = hash.finish();<br>
digestType!(typeof(hash)) result = hash.finish();<br>
<br>
are equivalent. But<br>
<br>
ubyte[4] result = hash.finish();<br>
<br>
does only work if hash is a CRC32 digest. It does not work for md5, sha1<br>
digests, etc.<br>
<br>
But I agree that examples are easier to read without auto, so I'll<br>
change them to use the explicit type where possible.<br>
</blockquote></div><br><div>Case in point, look how much information you just gave us that is completely obscured by 'auto' :)</div><div>My suggestion, simplify the example, or, at least the example associated with the direct function documentation:</div>
<div><pre class="d_code" style="background-color:rgb(252,252,252);padding:1ex;margin-left:3em;font-size:14px;border:1px solid rgb(204,204,204);width:auto;white-space:pre-wrap;word-wrap:break-word;color:rgb(0,0,102);text-align:justify">
 <span class="d_keyword" style="color:blue">auto</span> md5   = <span class="d_psymbol" style="text-decoration:underline">digest</span>!MD5(  <span class="d_string" style="color:red">"The quick brown fox jumps over the lazy dog"</span>);
 <span class="d_keyword" style="color:blue">auto</span> sha1  = <span class="d_psymbol" style="text-decoration:underline">digest</span>!SHA1( <span class="d_string" style="color:red">"The quick brown fox jumps over the lazy dog"</span>);
 <span class="d_keyword" style="color:blue">auto</span> crc32 = <span class="d_psymbol" style="text-decoration:underline">digest</span>!CRC32(<span class="d_string" style="color:red">"The quick brown fox jumps over the lazy dog"</span>);</pre>
</div><div>Those autos can be ubyte[n].</div><div>Though that said, looking at the API doc for finish(), it appears to return a dynamic array, not a static array as you say... so ubyte[] could be used everywhere, and that would be nice and clear?</div>