Problem with string.whitespace and newline
Jonathan M Davis
jmdavisProg at gmx.com
Sat Jun 11 18:56:49 PDT 2011
On 2011-06-11 18:46, Andrej Mitrovic wrote:
> I've said it before, but I'll say it again: this is such a common
> error that it needs a better error message. Something as simple as
> this will do:
> "foo can't take bar of type char[16]. Try using a slice: bar[]".
Have you created an enhancement request for it? If not, it's not likely to
happen.
Though honestly, this is a bit of a tough one, because all that the compiler
really knows is that the argument that you gave to the template function
didn't match any of that template function's overloads. It has no idea why.
And maybe there's an overload which is _supposed_ to take a static array for
some reason, and it's another argument to the function that you screwed up?
There's probably some sort of special-casing that the compiler could do when
trying to instantiating a template function and one of the arguments it was
given was a static array, but the compiler is generally designed to tell that
what you did doesn't work rather than tell you what you're supposed to do. So,
getting error messages to give suggestions (particularly when templates are
involved) can be tricky. It's been done before with the spellchecker, but I
don't know how straightforward it would be to do that sort of thing with
static arrays given that it has a much broader scope.
Template errors are just generally bad. They're definitely better than in C++,
but I still don't think that they're anywhere near good enough for a lot of
the more average programmers. If you start messing with them a lot, then the
template constraints are actually quite good at giving you a clue as to what's
wrong, but for newbies in particular, they're pretty incomprehensible.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list