🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.mac.oop.macapp3
1 messages
1 total messages Started by Alger, Jeff,VCA Wed, 27 Jan 1993 19:03
Re3: C++ (was re: bedrock defe
#393
Author: Alger, Jeff,VCA
Date: Wed, 27 Jan 1993 19:03
44 lines
2337 bytes
Alan et al,
 
Let's not forget in this trashing of C++ that there are some very good features
of the language that simply aren't used very much, the idioms Larry spoke of
(and I STRONGLY recommend that people attend his talk at MADACON).  As just one
of many examples, consider possibilities for smart pointers.
 
class foo {...};
class PFoo {
private:
    foo* fFoo;
public:
// various constructors, operator=, etc.
    foo* operator-> (void) { return fFoo; }
};
 
Now one can use a PFoo as a direct replacement for a foo* in almost every
circumstance.  It is the same four bytes and operator->, being inline, is the
same overhead as using a foo* directly.  What's the big deal?  Suppose, perhaps
only with a compile-time debug switch on, we make operator-> and other methods
a little more sophisticated:
 
1. Check to make sure fFoo is non-nil.  This traps nil pointers very
efficiently.
2. As suggested in my Frameworks article, keep a reference count in each foo,
counting how many PFoos there are out there.  Now, in foo's destructor make
sure the reference count is zero and raise an exception otherwise.  This traps
dangling pointers.
3. For that matter, when the reference count goes to zero put the foo into a
list of objects that should have been deleted and weren't, thereby trapping
memory leaks.
 
These are just a few of the things that one can do in C++ that have no
convenient counterpart in Pascal or most other efficiently compiled languages.
And if there is a performance concern, it is very easy to bracket them with
conditional compilation switches.  I am not really an apologist for C++ (I'll
pay the price for an OODL any day), but it continues to be the butt of a lot of
undeserved criticism.  Used wisely, I think C++ is actually one of the best
platforms for building robust code that still runs fast.
 
Regards,
Jeff Alger
SBM International
 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads