| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
March 05, 2009 Re: return in void functions | ||||
|---|---|---|---|---|
| ||||
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 | ||||
March 06, 2009 Re: return in void functions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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?
| |||
March 06, 2009 Re: return in void functions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Georg Wrede | "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. | |||
March 06, 2009 Re: return in void functions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | 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
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply