www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: return in void functions

reply bearophile <bearophileHUGS lycos.com> writes:
Nick Sabalausky:
 There has to be a better way to handle that.

Possible idea: allowing functions too (and not just function templates as in D2) to have an "auto" return type?
(In fact, I've been bitten by that before.)<

Me too, that's why I have started this thread. Bye, bearophile
Mar 05 2009
parent reply Georg Wrede <georg.wrede iki.fi> writes:
bearophile wrote:
 Nick Sabalausky:
 There has to be a better way to handle that.

Possible idea: allowing functions too (and not just function templates as in D2) to have an "auto" return type?

void main() { auto a = f(); // Here, store a in a struct, i.e. you need to know the type // so that you can have the right kind of struct for it. } auto f() { auto c = g(); return c; } auto g() { auto c = h(); return c; } Then in a library (probably not even documented with the actual return type -- an understandable omission by this time...) auto h() { auto c = i(); return c; } auto i() { auto c = j(); // where j() is a non-public function. return c; } ...etc. So, isn't it easier for the programmer to know what the data type is, without going for goose chases every time?
Mar 06 2009
parent reply "Nick Sabalausky" <a a.a> writes:
"Georg Wrede" <georg.wrede iki.fi> wrote in message 
news:goqlhm$bg5$1 digitalmars.com...
 bearophile wrote:
 Nick Sabalausky:
 There has to be a better way to handle that.

Possible idea: allowing functions too (and not just function templates as in D2) to have an "auto" return type?

void main() { auto a = f(); // Here, store a in a struct, i.e. you need to know the type // so that you can have the right kind of struct for it. } auto f() { auto c = g(); return c; } auto g() { auto c = h(); return c; } Then in a library (probably not even documented with the actual return type -- an understandable omission by this time...) auto h() { auto c = i(); return c; } auto i() { auto c = j(); // where j() is a non-public function. return c; } ...etc. So, isn't it easier for the programmer to know what the data type is, without going for goose chases every time?

You could probably just do: auto a = f(); Stdout.formatln("{}", typeof(a).stringof); // Debug But I still wouldn't want to have to do that. Of course, that could arguably be solved by having automatic documentation automatically resolve the "auto". Although that would require 3rd party doc generators to do much more involved parsing.
Mar 06 2009
parent bearophile <bearophileHUGS lycos.com> writes:
Nick Sabalausky:
 Of course, that could arguably be solved by having automatic documentation 
 automatically resolve the "auto".

This seems a ncie idea for ddoc. Bye, bearophile
Mar 06 2009