Please do not use 'auto' return types without thoroughly describing the interface

Neia Neutuladh neia at ikeran.org
Mon Dec 25 03:23:33 UTC 2017


If you have a function with a return type listed as `auto`, 
please thoroughly describe what interface the return value 
provides.

"Returns a forward range of Elem", where Elem is a template 
parameter, is fine, for instance.

But look at std.regex.RegexMatch.front:

"Functionality for processing subsequent matches of global 
regexes via range interface"

It has an example that mentions a `hit` property. Other parts of 
the RegexMatch interface mention `pre` and `post` properties. 
What are they? It is a mystery!

Turns out that the return type is a Captures struct, and that 
could be made explicit with little effort. (Such as 
https://github.com/dlang/phobos/pull/5963.)

This *is* redundant. Looking at the source code lets you find the 
return type in less than thirty seconds. Or you can put into your 
code: `pragma(msg, ReturnType!(func).stringof);` However, I 
imagine we'd lose a lot of people in the "see missing 
documentation" → "look at source code" step.


More information about the Digitalmars-d mailing list