toString ugliness

Nick Sabalausky a at a.a
Sun Dec 7 14:29:10 PST 2008


"Christopher Wright" <dhasenan at gmail.com> wrote in message 
news:ghhbn3$2u32$1 at digitalmars.com...
> Ary Borenszweig wrote:
>> Jarrett Billingsley escribió:
>>> On Sun, Dec 7, 2008 at 7:12 AM, Ary Borenszweig <ary at esperanto.org.ar> 
>>> wrote:
>>>>> definition of toString that does match.  Most of the time ADL leads to
>>>>> confusing behavior, which is why it was dropped in D.
>>>> But the overloading is obvious! It looks for toString(...) and it 
>>>> founds it
>>>> in the class, but the overloading is wrong. So for me, it should keep
>>>> looking in the enclosing scopes.
>>>
>>> That's why I said "*most* of the time" ;)  I'll agree that it's a bit
>>> counterintuitive, but I'd rather have the compiler be a little stupid
>>> in this regard than to pay the price of unexpected function matches
>>> for a little bit of convenience.
>>
>> Ah, I see. Well, I'd like to see such an example then. :-P
>
> It usually won't be an issue, I think. You'll give your functions 
> descriptive names, and you won't have overloads in different scopes that 
> take similar arguments. So any example I give will probably seem 
> contrived. I certainly have only encountered this compiler error a bare 
> handful of times, and only with toString.
>
> That said, errors of this kind would be difficult to track down, and the 
> workaround is very simple once you know it -- and not that difficult to 
> come up with if you don't. I think I came up using .toString without 
> having anyone tell me about it, and if I hadn't, I would have used the 
> fully qualified name (or an alias).

I kind of like Ruby's requirement that accessing "this.whatever" *must* be 
done like "@whatever" (with the "this." part not being needed). Omitting the 
@ means you're talking about either a local identifier or a global one. I 
don't know if that stuff applies to member functions as well or if it's just 
member vars, but if it did apply to member funcs then that would certainly 
solve the "finding the correct toString" issue. Of course, that would 
probably be way too big of a syntax change for D, though. 





More information about the Digitalmars-d mailing list