On Saturday, 28 May 2016 at 13:37:55 UTC, maik klein wrote:
I really like D's syntax for lambdas and I usually write code
like this
auto v = validationLayers[].all!((layerName){
return layerProps[].count!((layer){
return strcmp(cast(const(char*))layer.layerName,
layerName) == 0;
}) > 0;
});
But this gives you basically 0 helpful error messages:
"Error: template
breeze.graphics.context.createContext.all!((layerName)
{
return layerProps[].count!((layer)
{
return strcmp(cast(const(char*))layer.layerName, layerName) ==
0;
}
) > 0;
}
).all cannot deduce function from argument types
!()(const(char*)[]), candidates are:
/usr/include/dmd/phobos/std/algorithm/searching.d(113,10):
breeze.graphics.context.createContext.all!((layerName)
{
return layerProps[].count!((layer)
{
return strcmp(cast(const(char*))layer.layerName, layerName) ==
0;
}
) > 0;
}
).all(Range)(Range range) if (isInputRange!Range &&
is(typeof(unaryFun!pred(range.front))))
dmd failed with exit code 1"
For example I simply forgot to import `count`, nothing in the
error message is really helpful and the only way to know for
sure is to rip the function apart, which is not a very fun
thing to do.
You can't also rip it apart easily because in the case above I
implicitly capture `layerName` in the closure for `count`.
What are you thoughts on this?
You are not the first who complains - the issue tracker [1] is
full with issues about bad error messages
https://issues.dlang.org/show_bug.cgi?id=15893
https://issues.dlang.org/show_bug.cgi?id=15614
https://issues.dlang.org/show_bug.cgi?id=15597
https://issues.dlang.org/show_bug.cgi?id=15215
...
On the recent Slant about Programming languages [2] "Error
messages can be confusing, especially for newcomers" was the
highest up-voted Con of D.
[1]
https://issues.dlang.org/buglist.cgi?quicksearch=error%20messages&list_id=208649
[2]
http://www.slant.co/topics/5984/~productivity-enhancing-well-designed-and-concise-rather-than-just-popular-or-time-tested-programming-la