On 12/23/12, Benjamin Thaut <[email protected]> wrote: > I just created my first pull request for druntime and there where > multiple commonets to _not_ use auto. I don't quite understand > why it shouldn't be used in library functions. If it should not > be used why is it in the language in the first place? > > Kind Regards > Benjamin Thaut
auto is mainly useful for complex return types or for nested types which you can't otherwise declare (called voldemort types), e.g.: auto x = joiner([""], "xyz"); writeln(typeid(x)); // => std.algorithm.joiner!(string[], string).joiner.Result When the type is simple you should use the name of the type instead of auto because it serves as useful documentation, especially in library functions where you might later have to fix a bug. It's really useful to know exactly what type each variable is without having to waste time e.g. looking at function declarations to figure out the return type.
