Re: win32 design patterns

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



The "fact" that exceptions lead to reduced code size is a myth.
In reality, you can save up to 20% binary code size (coming from
actual code experiments) by disabling C++ exceptions. Where
I work C++ exceptions are strictly prohibited since we care
about downloadable code size. Not to mention the hidden
complexity in properly handling C++ exceptions.

As for two-phase initialization - this is not an anti-pattern. It's
quite useful in certain C++ designs because the initialization
can now be decoupled from the construction and can happen
in a completely different part of the code. I prefer the term
multi-phase initialization - initialization can happen in multiple
calls, not a single one. This helps with information hiding and
reduced coupling since different pieces know about the
initialization data. Or you might prefer the term setup since
initialization in C++ is usually associated with the constructor.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@xxxxxxxx
MVP VC FAQ: http://vcfaq.mvps.org
=====================================

"Alf P. Steinbach" <alfps@xxxxxxxx> wrote in message
news:13sd25p8r6g1r15@xxxxxxxxxxxxxxxxxxxxx
* Alex:

What are "Win32 design patterns"? Any design patterns are specific to
WIN32?

I don't know, but judging from Google search results it's just a
concatenation of two job requirements: familiarity with Win32 (presumably
the API), and with design patterns.



I know some design patterns written by Gamma (and 3 more are there).

It could be meaningful to label some of the patterns common in Win32
programming as "design patterns". But even more meaningful to label them
as "anti patterns"! E.g., the pattern of using default construction +
init method, common in MFC and in all COM-based code. Or, for another
Win32 anti pattern, the pattern of using HRESULTs to communicate failure
even within C++ code, instead of exceptions. Which reduces C++ to the
level of C (increasing code complexity and size).

Cheers, & hth.,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


.



Relevant Pages

  • Re: Observer Design Pattern
    ... Design Patterns are not the kind of thing that you can turn into a reusable coding library. ... Observer is one of the exceptions to this rule; but it's only a partial exception for the reasons that you have already pointed out in your post. ... require 'singleton' ...
    (comp.object)
  • Re: win32 design patterns
    ... actual code experiments) by disabling C++ exceptions. ... Source code size and complexity matters. ... Exceptions automate failure handling. ... multi-phase initialization - initialization can happen in multiple ...
    (microsoft.public.vc.language)
  • Re: win32 design patterns
    ... exceptions were not part of the original C++ language. ... Source code size and complexity matters. ... quite useful in certain C++ designs because the initialization ... multi-phase initialization - initialization can happen in multiple ...
    (microsoft.public.vc.language)
  • Re: atl-com-exe - Init. obj in constructor of com class
    ... > The problem is that when I initialise it in the CMyClass constructor, ... It appears that you are using C++ exceptions in Webtool, ... translate into an appropriate HRESULT error code. ... This means that you cannot perform initialization in constructor. ...
    (microsoft.public.vc.atl)
  • Re: OO conventions
    ... Whatever the Imageinitialization does, ... useful idiom, and it can serve several kinds of purposes, many but not ... since it was considered bad to have code in the constructor ... which could throw exceptions. ...
    (comp.lang.python)