On 4/10/13 8:44 AM, Manu wrote:
On 10 April 2013 22:37, Andrei Alexandrescu
<[email protected] <mailto:[email protected]>>
wrote:

    On 4/10/13 2:02 AM, Manu wrote:

        I do use virtual functions, that's the point of classes. But most
        functions are not virtual. More-so, most functions are trivial
        accessors, which really shouldn't be virtual.


    I'd say a valid style is to use free functions for non-virtual
    methods. UFCS will take care of caller syntax.


Valid, perhaps. But would you really recommend that design pattern?
It seems a little obscure for no real reason. Breaks the feeling of the
OO encapsulation principle somewhat.

It may as well be a mistake that nonvirtual functions are at all part of a class' methods. This has been quite painfully seen in C++ leading to surprising conclusions: http://goo.gl/dqZrr.

I've started using UFCS more recently, but I'm still wary of overuse
leading to unnecessary obscurity.

UFCS is a "slam dunk" feature - simple and immensely successful. The only bummer is that UFCS arrived to the scene late. If I designed D's classes today, I'd only allow overridable methods and leave everything else to free functions.


Andrei

Reply via email to