Function call without parentheses?
Jacob Carlborg
doob at me.com
Tue May 10 12:23:10 PDT 2011
On 2011-05-10 16:12, Rainer wrote:
> Thanks for the explanation. I'm new to D and I haven't learned the @property syntax yet.
>
> The problem is that it took me hours to find this simple bug. I wouldn't have named
> the variable and method both isValid myself, but this piece of code is coming from Java
> where variables and methods can have the same name since method invocations always require parentheses.
>
> In C++ this wouldn't compile since all members--be they variables or methods--have to be named uniquely.
>
> Here you can't tell from looking at the code what isValid actually refers to. It doesn't look like a clean design.
> I would never have thought that this method actually calls itself. How would I access the variable isValid here?
Either name it something else or maybe you can use "this".
> Debugging doesn't work all that well under Linux which made it even more difficult to find the error.
> Add to that the fact that the stack probably had been corrupted from the recursive method call (stacktrace pointing to
> something unrelated) and you're this close to giving up on this language.
>
> I'd rather have the compiler issue an error or warning when you have a variable and method with the same name since you
> can't access the variable anyway.
>
> If property will be enforced I reckon that plenty of code is going to break. IMHO it doesn't look like a feature which is
> worth the trouble and confusion it causes.
>
> Cheers,
> Rainer
Ruby works the same, but in Ruby all instance variables start with a @ sign.
--
/Jacob Carlborg
More information about the Digitalmars-d-learn
mailing list