Op 28-Oct-16 om 23:54 schreef Richard:
> Paavo Helde <
myfir...@osa.pri.ee> spake the secret code
> <
76OdnSrV0PZKJI7F...@giganews.com> thusly:
>
>> On 28.10.2016 23:04, Mr Flibble wrote:
>>> The correct approach in this instance is to not use MFC at all: MFC is
>>> egregious 1990s dross.
>>
>> Your advice is correct, and absolutely useless because nobody is going
>> to rewrite this application.
>
> Yes, the advice is useless, but the problem here doesn't strike me
> as being one that is because MFC was written in the 90s. MFC is a
> creature of its time, sure, but that is just reflected in its idea
> that everything is derived from CObject and we have a large
> monolithic framework. ATL also dates from the 90s but uses a
> different philosophy for class hierarchies.
It is not just different philosophy but also constraints they had to
deal with at the time. MFC is from the early nineties when the Microsoft
C++ compiler supported little more than C with classes (no templates, no
exceptions, no standard library), and the framework was still targeting
16-bit Windows running on 386 processors. ATL is from the late nineties
when the C++ dialect understood by the Microsoft compiler of that era
had much more in common with what we would consider C++ today.
As far as everything being derived from a common "object" class; this is
not unique to MFC, you see it also in Python, Java, C#...etc, where the
"object" class is roughly the equivalent of a void*.
> Anyway, my interest in this discussion wasn't to just be an idiot and
> say "MFC is junk from the 90s, who cares", because doing so is just
> throwing the baby out with the bathwater. MFC isn't the first, nor
> is it the last, application framework that considered inheritance to
> be the best vehicle for reuse. Inheritance for reuse is way overdone
> in any language supporting inheritance: JavaScript, Java, C#, C++,
> etc.
Having a common base class for all classes is partially motivated by the
limitations of these languages. For example Java and C# do not support
templates and originally did not support generics (a sort of a dumbed
down variation of templates). So for example to have reusable container
classes it helps to have everything derived from a single base class.
> My interest was in getting at the root of the problem. It sounded
> (and still sounds) to me that an attempt was made to place a
> responsibility on the view that it shouldn't have and that's why we
> needed dynamic_cast<>.
>
> If we don't stop to consider the design philosophy of the frameworks
> we're using or the design principles involved when we write code, we
> aren't working smarter, we're just working harder.
The question is what were the motivations for a framework to do things
in a certain way, and if they do still apply. In case of MFC many of its
design choices can be explained if you look at what they had to work
with at the time (a very limited subset of the C++ language as we know
it today, targeting slow hardware), however most of the choices made
back then no longer make sense today. It is disappointing to see that
today the most popular C++ GUI frameworks (Qt, WxWidgets) still clearly
have their roots in the nineties.