How about "auto" parameters?

Ary Manzana ary at esperanto.org.ar
Thu Jun 9 00:19:41 PDT 2011


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. :-)


More information about the Digitalmars-d mailing list