does D already have too many language features ?
H. S. Teoh
hsteoh at quickfur.ath.cx
Mon Apr 15 01:22:06 UTC 2019
On Sun, Apr 14, 2019 at 08:14:17PM +0000, JN via Digitalmars-d wrote:
[...]
> For me the toughest part of D is dealing with heavily templated code.
> Documentation often uses auto for those. Unfortunately IDEs don't
> always help with templates, so often I am stuck with an object and I
> don't even know what is the type of it and what I can do for it.
> Without example code, I am usually stuck. Also, many routines return
> something like Result!(Foo, Bar). In these cases it's recommended to
> use auto, which is OK for local variables, but if you want to pass the
> result to some other function - good luck figuring out what is the
> actual type of the variable so that you can declare it in the function
> parameters list.
There's no need to declare it yourself. Just use:
alias MyType = typeof(someFunc(a,b,c));
MyType x;
...
x = someFunc(a,b,c);
Most of the time, when the return type is something like Result!(...),
usually the intent is that user code *shouldn't* depend on the concrete
type, because it may arbitrarily change between library versions. Using
typeof() ensures that it won't break if the return type does change.
T
--
Some days you win; most days you lose.
More information about the Digitalmars-d
mailing list