473,763 Members | 5,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sutter's Pimples: Good, Bad, or Ugly?

Pete Vilder mentioned this a few days back. This is the "Compiler-Firewall
Idiom", or pimple. It's similar to an approach taken in some Java designs.
AAMOF, when I saw it in Java, my first reaction was "Oh by Þor! It's
freakin' headers all over again!"

My greatest misgiving about the approach is that it seems overly
complicated. I /feel/ as if there is a better more 'conventional' way of
dealing with the separation of interface and implementation. OTOH, it's
clear to me that the people who have advocated it are not stupid.*

Here's the discussion: http://www.gotw.ca/publications/mill05.htm

What do you make of it?

*(Sutter does serve the Dark Lord, but that's a different story. Lippman,
too has passed into darkness.)

--
p->m == (*p).m == p[0].m
http://www.kdevelop.org
http://www.suse.com
http://www.mozilla.org
Jul 22 '05
34 4580
Alf P. Steinbach wrote:
* "Steven T. Hatton" <su******@setid ava.kushan.aa> schriebt:
Phlip wrote:
> But Pimpl is for emergencies, after a design is committed. C++ was
> designed to permit compilation firewalls based on abstract types; Pimpl
> abstracts a concrete type.


That was the kind of answer I was looking for.


I'm hereby giving up on you. You chose the only response that was all
dress
and no actual content. That fancy dressed "girl" is a boy, Steven.

I didn't say it was the correct answer. All I intended was that it seems to
suggest there are better ways to address some or most circumstances in
which the CFI would be used. I have to say the concern about compile time
makes me a bit uneasy. If anything, I would say the long compile times are
a symptom not the disease.

So, I was looking at Martin's book, but I bought these instead:
http://www.josuttis.com/libbook/index.html
http://www.oreilly.com/catalog/cpluspluspr/

Have I gained any redemption?
--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org
Jul 22 '05 #21
Alf P. Steinbach wrote:
Steven T. Hatton schriebt:
Phlip wrote:
But Pimpl is for emergencies, after a design is committed. C++ was
designed to permit compilation firewalls based on abstract types; Pimpl abstracts a concrete type.
That was the kind of answer I was looking for.

I'm hereby giving up on you. You chose the only response that was all dress and no actual content. That fancy dressed "girl" is a boy, Steven.


Did I step into the middle of something?

I don't see how a synopsis of DIP in C++ terms, to avoid Pimpl, scores as
"no actual content". Defend your statement.

--
Phlip
http://www.xpsd.org/cgi-bin/wiki?Tes...UserInterfaces
Jul 22 '05 #22
Steven T. Hatton wrote:
I didn't say it was the correct answer. All I intended was that it seems to suggest there are better ways to address some or most circumstances in
which the CFI would be used. I have to say the concern about compile time
makes me a bit uneasy. If anything, I would say the long compile times are a symptom not the disease.
The implication is a healthy design in C++ naturally firewalls compilation
without extra effort.
So, I was looking at Martin's book, but I bought these instead:
http://www.josuttis.com/libbook/index.html
http://www.oreilly.com/catalog/cpluspluspr/

Have I gained any redemption?


No. Get Martin's book too. And /Design & Evolution of C++/ by Bjarne.

--
Phlip
http://www.xpsd.org/cgi-bin/wiki?Tes...UserInterfaces
Jul 22 '05 #23
* "Phlip" <ph*******@yaho o.com> schriebt:
Alf P. Steinbach wrote:
Steven T. Hatton schriebt:
Phlip wrote: But Pimpl is for emergencies, after a design is committed. C++ was
> designed to permit compilation firewalls based on abstract types; Pimpl > abstracts a concrete type. That was the kind of answer I was looking for.

I'm hereby giving up on you. You chose the only response that was all

dress
and no actual content. That fancy dressed "girl" is a boy, Steven.


Did I step into the middle of something?


Nope, you just gave meaningless advice.

I don't see how a synopsis of DIP in C++ terms, to avoid Pimpl, scores as
"no actual content". Defend your statement.


It's really you who should defend why DIP ("Dependency Inversion Principle",
a silly elevation of the common notion of abstract interface to acronym
status) is a description of pimpl -- which it isn't. Now you state that
is a way to avoid pimpl. Well, it isn't that either.

It is an alternative to pimpl in the case where you don't need implementation
inheritance, as I noted & described in one short sentence in my first posting
in this thread -- read that single sentence instead of Mr Martins ramblings.

Mr Martin uses umpteen pages of text and a lot of impenetrable language and
trivialities, including inventing new terminology, to try to get across the
simple, trivial point of how an abstract interface works (which I did in one
sentence), without quite managing it, and does not even mention pimpl as far
as I can see. Nor did it seem like he mentioned implementation inheritance.
But I just skimmed the thing right now to see roughly what he was trying to
write this time, in case your response meant he actually wrote something.

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #24
Alf P. Steinbach wrote:
Mr Martin uses umpteen pages of text and a lot of impenetrable language and trivialities, including inventing new terminology, to try to get across the simple, trivial point of how an abstract interface works (which I did in one sentence), without quite managing it, and does not even mention pimpl as far as I can see. Nor did it seem like he mentioned implementation inheritance. But I just skimmed the thing right now to see roughly what he was trying to write this time, in case your response meant he actually wrote something.


Okay. I thought you might have a point, or might have understood ours. No
such luck.

To anyone else who has followed this far: Both Lakos and Martin advise to
break a dependency cycle with an abstract bases class, even if there's no
other reason for one to exist.

Martin doesn't mention Pimpl because it's not a goal, it's a temporary hack.
Don't write that which you must then retract.

--
Phlip
http://www.xpsd.org/cgi-bin/wiki?Tes...UserInterfaces
Jul 22 '05 #25
Phlip wrote:
[snip]
To anyone else who has followed this far: Both Lakos and Martin advise to
break a dependency cycle with an abstract bases class, even if there's no
other reason for one to exist.
A fully abstract base class seems like a lot of effort just to break a
dependency. Certainly there are many other reasons to use them, but I
don't think I would create one just for this.
Martin doesn't mention Pimpl because it's not a goal, it's a temporary hack.
Don't write that which you must then retract.


I don't see anything temporary (or hackish) about pimpl. Can you clarify?

-- Pete
Jul 22 '05 #26
* "Phlip" <ph*******@yaho o.com> schriebt:

Okay. I thought you might have a point, or might have understood ours. No
such luck.


What I understand from your writings is that you pass about silly acronyms,
and that you know a quite a few ways to steer a discussion away from the
technical and to the personal while giving the impression of being reasonable.

So it's probably futile to ask whether you have a C++-related point.

Goodbye, phlip.

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #27
"Pete Vidler" <pv*****@mailbl ocks.com> wrote
Phlip wrote:
[snip]
To anyone else who has followed this far: Both Lakos
and Martin advise to break a dependency cycle with
an abstract bases class, even if there's no other reason
for one to exist.
A fully abstract base class seems like a lot of effort just
to break a dependency.


No effort is too great to eliminate unncessary dependencies. It wouldn't be
an exaggeration to say that gratuitous coupling is the software world's
biggest failing.
Certainly there are many other reasons to use them,
but I don't think I would create one just for this.


You would if you worked in an environment that doesn't allow lazy shortcuts.
Martin doesn't mention Pimpl because it's not a goal,
it's a temporary hack. Don't write that which you must
then retract.


I don't see anything temporary (or hackish) about pimpl.
Can you clarify?


Temporary or not, it's definitely a hack that's meant to circumvent C++'s
integration of some implementation details in the interface. There's nothing
elegant about the pimpl idiom. It's just a solution to a certain class of
problems.

Claudio Puviani
Jul 22 '05 #28
* "Claudio Puviani" <pu*****@hotmai l.com> schriebt:

No effort is too great to eliminate unncessary dependencies.


If only more folks did invest that effort...

Certainly there are many other reasons to use them,
but I don't think I would create one just for this.


You would if you worked in an environment that doesn't allow lazy shortcuts.


What are some examples of lazy shortcuts for this problem (header file
dependency) in C++?

Martin doesn't mention Pimpl because it's not a goal,
it's a temporary hack. Don't write that which you must
then retract.


I don't see anything temporary (or hackish) about pimpl.
Can you clarify?


Temporary or not, it's definitely a hack that's meant to circumvent C++'s
integration of some implementation details in the interface.


No need to resort to name calling. It's a technique. Like most everything
in C++ it's at a lower level than the conceptual abstraction, but it's not
particularly clever or elegant, nor particularly low-level, so it is in no
sense that I recognize a hack, and using a derogatory term for it seems to be
in conflict with your first implied wish that it be used more (not less).

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #29
Pete Vidler wrote:
Phlip wrote:

To anyone else who has followed this far: Both Lakos and Martin advise to break a dependency cycle with an abstract bases class, even if there's no other reason for one to exist.


A fully abstract base class seems like a lot of effort just to break a
dependency. Certainly there are many other reasons to use them, but I
don't think I would create one just for this.


It's better than a Pimpl.
Martin doesn't mention Pimpl because it's not a goal, it's a temporary hack. Don't write that which you must then retract.


I don't see anything temporary (or hackish) about pimpl. Can you clarify?


Define "coupling" as "X must change only because Y changed".

C++ has a special category of coupling, which is "X must recompile only
because Y's header's recompiled". If you have compile-time coupling, the
odds are very high you also have logical coupling. Changing Y requires you
to re-think X. (Contrarily, low-compile time coupling is not evidence of low
logical coupling!)

Cleaning up logical coupling, in C++, typically leads to less compile-time
coupling. But the best way to do that is abstract base classes - which only
contain a bunch of pure virtual methods, and maybe some constants. No
behavior, no extra #include headers, etc. So they are like Pimpl, but they
reflect logical design advances.

By contrast, if you have poor compile times, you might install a Pimpl
without changing the logical coupling.

This is all fuzzy - presence of Pimpl does not imply logical coupling. But
Pimpl is still just a hack, not a design goal. Use it for an iteration, but
incrementally upgrade the design towards DIP.

--
Phlip
http://www.xpsd.org/cgi-bin/wiki?Tes...UserInterfaces


Jul 22 '05 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
1817
by: Steven T. Hatton | last post by:
Pete Vilder mentioned this a few days back. This is the "Compiler-Firewall Idiom", or pimple. It's similar to an approach taken in some Java designs. AAMOF, when I saw it in Java, my first reaction was "Oh by Þor! It's freakin' headers all over again!" My greatest misgiving about the approach is that it seems overly complicated. I /feel/ as if there is a better more 'conventional' way of dealing with the separation of interface and...
2
4049
by: Debajit Adhikary | last post by:
I'm still pretty new to design patterns... I was wondering, is there any difference between the Bridge Pattern and Herb Sutter's Pimpl Idiom? Both delegate responsibility to an implementation and thus allow a clear and flexible separation of interface and implementation such that the implementation can be changed freely.
7
2326
by: Mikhail N. Kupchik | last post by:
Hi All. I have a question regarding Herb Sutter's idiom of implementation of operator= via nonthrowing swap() member function, to guarantee strict exception safety. The idea of the idiom is shown by the example: -- code fragment 1 ---------------------------------------------------- class MyClass
3
6799
by: swengtoo | last post by:
In his book "More Effective C++", Scott Meyer suggests in "Item 4" to "Avoid gratuitous default constructors". To summarize his claims against default constructors for "the right classes" he states that: ================== START QUOTE ============= "A default constructor is the C++ way of saying you can get something for nothing. Constructors initialize objects, so default constructors initialize objects without any information from...
9
1594
by: Joel Hedlund | last post by:
Hi! I need some input on my use of metaclasses since I'm not sure I'm using them in a pythonic and graceful manner. I'm very grateful for any tips, pointers and RTFMs I can get from you guys. Below, you'll find some background info and an executable code example. In the code example I have two ways of doing the same thing. The problem is that the "Neat" version doesn't work, and the "Ugly" version that works gives
24
2148
by: Noah Roberts | last post by:
Item #1 in the More Exceptional C++ book uses the following construct: fstream in; .... process( in.is_open() ? in : cin,...); Where process has been shown as having various multiple different
0
1143
by: Gennaro Prota | last post by:
Hi, after several "tweaks" I think I've finally found a file layout which I like for my code (in terms of where the copyright line and the license reference go, where the vim modeline etc.). For included files, I've stuck so far to the suggestion in C++ Coding Standards which says: Don't try to be clever: Don't put any code or comments before and after the guarded portion, and stick to the standard form
206
8364
by: WaterWalk | last post by:
I've just read an article "Building Robust System" by Gerald Jay Sussman. The article is here: http://swiss.csail.mit.edu/classes/symbolic/spring07/readings/robust-systems.pdf In it there is a footprint which says: "Indeed, one often hears arguments against building exibility into an engineered sys- tem. For example, in the philosophy of the computer language Python it is claimed: \There should be one|and preferably only one|obvious...
20
4205
by: benhoyt | last post by:
Hi guys, I've been using Python for some time now, and am very impressed with its lack of red tape and its clean syntax -- both probably due to the BDFL's ability to know when to say "no". Most of the things that "got me" initially have been addressed in recent versions of Python, or are being addressed in Python 3000. But it looks like the double underscores are staying as is. This is probably a good thing unless there are better...
0
9387
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10002
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.