Uniform call syntax for implicit this.

spir denis.spir at gmail.com
Thu Feb 3 12:50:17 PST 2011


On 02/03/2011 08:15 PM, Michel Fortin wrote:
> On 2011-02-03 13:42:30 -0500, Jonathan M Davis <jmdavisProg at gmx.com> said:
>

>> Except that if you have both a member function foo and a free function foo, how
>> can you tell the compiler which to use?
>
> Indeed, that's a problem. The solution is to sidestep the problem. :-)
>
> We just have to disallow declaring a module-level function and a class-level
> function with the same name and the same parameter types (including 'this' in
> the parameters).
>
> void foo(A a, int i);
>
> class A {
> void foo(int i); // error, same as foo(A, int)
> }
>
> If the module-level function is in a different module, then you can use the
> module name to disambiguate if necessary. If they're in the same module, the
> compiler catches the error during semantic analysis of the module.
>
> I'm not too sure how disruptive this change would be to existing code. I'm
> under the impression that this situation is rare, but I can't say for sure.

How can you propose this, Michel? Complexify the language, and any 
implementation, just for a non-feature that makes code very hard to decode, by 
requiring a double mental rewriting operation:
     foo(i) --> this.foo(i) --> foo(this,i)
what advantage does this feature provide? None. What additional drawback: see 
thread above.

Denis
-- 
_________________
vita es estrany
spir.wikidot.com



More information about the Digitalmars-d mailing list