How about "auto" parameters?
Jonathan M Davis
jmdavisProg at gmx.com
Thu Jun 9 00:54:56 PDT 2011
On 2011-06-09 00:19, Ary Manzana wrote:
> On 6/9/11 9:56 AM, Jonathan M Davis wrote:
> > I don't think that there's any question that template error messages
> > could be improved, and they likely will be, but by their very nature,
> > reporting template-related errors seems to be a difficult task to
> > adequately solve. It's one of the things that many people complain about
> > with C++. Template constraints improve the situation considerably.
>
> I don't think the problem is with templates. If I try to compile this:
>
> ===
> void foo(int param) {
> return param * 2;
> }
>
> void main() {
> foo(3);
> }
> ===
>
> it says:
>
> main.d(2): Error: * has no effect in expression (param * 2)
>
> WTF? Don't make me think. I just really want to know that I'm returning
> from a void function and I can't do that.
>
> Let's assign foo(3) to something:
>
> ===
> void foo(int param) {
> return param * 2;
> }
>
> void main() {
> auto x = foo(3);
> }
> ===
>
> It says:
>
> main.d(2): Error: * has no effect in expression (param * 2)
> main.d(6): Error: variable main.main.x voids have no value
> main.d(6): Error: expression foo(3) is void and has no value
>
> Really? Voids have no value? That's good to know, I didn't know that
> voids have no value.
>
> Mmm... those are messages to be read by the compiler, not by the user.
> The compiler is expecting something that's not void and it is getting a
> void thing. The message it generates is "Voids has no value".
>
> The problem are not templates or templates messages. The problem is that
> the very basic compiler error messages are targeted at the compiler, not
> the developer.
>
> And then this:
>
> ===
> void main() {
> const x = 1;
> x = 3;
> }
> ===
>
> main.d(3): Error: variable main.main.x cannot modify const
>
> What do you mean when you say that the variable x cannot modify const?
> Wait, I desguise myself as Tarzan and now I understand. It should be
> "Error: trying to modify const variable main.main.x".
>
> There is an excellent book called "Don't make me think". When I see
> "variable main.main.x cannot modify const" I have to think a little to
> understand that that means "variable main.main.x is const and cannot be
> modified". Don't make me think. :-)
Template error messages _do_ tend to be hideous. But that doesn't mean that
normal errors are the best either. And as I said, templates often end up
reporting exactly the same errors that you'd get if you wrote the code by
hand, it's just that the errors are then in the template and generally harder
to understand, because there's a good chance that it's not the code that you
write.
But regardless, none of these error messages are intended to be "read by the
compiler." They're all intended to be read by humans. It's just that you don't
find the choice of wording to be particularly understandable. However,
everything that it's saying is correct. If you find particular error messages
to be bad - particularly if you can think of better alternatives - then create
enhancement requests for them in bugzilla. Then perhaps we'll get better error
messages. But remember that the compiler doesn't know what you're trying to
do. It only knows what you told it to do, so its messages tend to be targetted
at telling you that what you're doing isn't working rather than telling you
what you should be doing instead. So, error messages are often not that great
simply because the compiler is not a mind-reader. Still, if you have
suggestions for improvements to error messages, please submit them to bugzilla
so that the error messages can be improved.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list