嗯嗯,当时我还写邮件问了他一个关于这篇Paper的技术问题,以下:
pongba wrote:
> Dear, Dr Stroustrup:)
>
> I have a specific question regarding the design rationale of Open
> Multi-Methods for C++.
> The proposed way of making a method dynamically-overloadable is to
> declare each of its parameters virtual:
>
> void foo(virtual X&, virtual Y&);
>
> While this approach seems intuitive w.r.t. the design of virtual
> functions in C++, I think it has a major limitation, that is, it left
> the choice of whether a method is dynamically-overloadable to the
> implementer of that method, rather than the final user.
>
> So, would it be a lot more flexible if we let the user decide whether
> dynamic dispatch is performed, such as:
>
> void foo(X&, Y&);
> void foo(X&, Z&);
>
> X& x = ...;
> Y& y = ...;
> foo(virtual x, virtual y); // or virtual foo(x, y);
>
> This approach has another advantage - it transparently makes existing
> code dynamically-overloadable.
but is that an advantage?
>
> Plus, it enables the client code to say:"Hey, I know I have a
> reference here whose dynamic type I don't, but I JUST want static
> overload OK?!", which is something the original design doesn't support
> (the dynamic dispatch is always performed if the type of an argument
> is indeterminable at compile-time).
The snag that I see is that to get the far most frequently desired
result, you have to say something extra and if you forget you'll in most
cases quietly get the wrong result. I suspect that would be a very nasty
little language design error.
看了BJ的回复,我只能说,姜,还是老的辣。
这种理念,还有Anders设计C#里面的一些理念,是真正的PL practical research的精神,比起关在象牙塔里面捣鼓什么killer&fancy语言特性的来说要更为可贵。
--
刘未鹏(pongba)|C++的罗浮宫
http://blog.csdn.net/pongbaTopLanguage
http://groups.google.com/group/pongba