On 17-05-2012 16:22, Steven Schveighoffer wrote:
On Thu, 17 May 2012 09:10:18 -0400, Tobias Pankrath
<tob...@pankrath.net> wrote:

This does not work and I can see why.

---
auto foo(int x)
{
if(x < 0)
return foo(-x);
return x;
}
----

DMD 2.059 says:
oopsc/compiler/test.d(7): Error: forward reference to foo
oopsc/compiler/test.d(14): Error: forward reference to foo

For the human reader it is easy to see that the return type of
foo should be int.

At this point, I think the human should intervene:

int foo(int x)
...

I would *hate* to have to read code like yours to try and understand it.

-Steve

I have to agree. Sometimes auto can be over-used. Even in functional languages with H-M type inference, I tend to always make my functions have explicit signatures (unless they're supposed to be generic). It's just clearer to the person reading the code later on.

--
- Alex

Reply via email to