home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!doug.cae.wisc.edu!umn.edu!nano!kotula
- From: kotula@nano.cs.umn.edu (Jeff Kotula)
- Newsgroups: comp.lang.c++
- Subject: Re: Return value for the constructors.
- Message-ID: <kotula.714615837@nano>
- Date: 24 Aug 92 00:23:57 GMT
- References: <1992Aug19.231926.28218@sunb10.cs.uiuc.edu> <2273@devnull.mpd.tandem.com> <matt.714318343@centerline.com> <2284@devnull.mpd.tandem.com> <matt.714407976@centerline.com>
- Sender: news@news2.cis.umn.edu (Usenet News Administration)
- Distribution: usa
- Organization: University of Minnesota
- Lines: 51
- Nntp-Posting-Host: nano.cs.umn.edu
-
- In <matt.714407976@centerline.com> matt@centerline.com (Matt Landau) writes:
-
- >The fact that both of these approaches leave you with the potential for
- >using an incompletely initialized object (the very thing constructors in
- >C++ were supposed to prevent!) points to a basic shortcoming in most of
- >the current implementations of the language.
-
- Do any languages handle this cleanly? None leap to mind...
-
- >The underlying point is that without a decent exception system, there
- >is **NO** good way to deal with the problem of constructor failures.
- >There are several different not-so-good ways to choose from; which one
- >you choose depends on the nature of the system you're writing.
-
- >Even *with* a decent exception system, the problem doesn't just go away.
- >Exceptions provide a mechanism and a framework within which one can deal
- >with this problem (as well as many other problems). The design skills
- >and engineering discipline needed to use exceptions both correctly and
- >robustly are still not to be underestimated.
-
- Absolutely. The approach you've outlined is what I've been using and it
- seems to work pretty well. You're final point is important because I've
- found that programmers dislike dealing with error situations and tend
- to simply ignore them. All the discussions elsewhere on how to improve
- software quality are a bit premature until we can overcome this tendency.
-
- Another aspect of this problem hasn't been discussed at all: what about
- operator overloading? Unless no operator functions can fail (probably
- unlikely in anything more complicated that a numerical type) you can't
- really use operator overloading and check for errors.
-
- One way you could is to (as has been mentioned) have a status code (a bit
- will generally not be enough information to recover from an error) in the
- object and *propogate* errors back to the final result-object of the
- expression. This is Ugly. Are programmers going to check the status of
- an object resulting from an expression when 50%(?) of all malloc or new
- calls are not verified?
-
- Anyway, the language that solves this problem elegantly and robustly is
- probably a long way off, so I think we need to come up with useful
- techniques and programming practices rather than rely on a new feature in
- a language that follows a tradition of ignoring the problem.
-
- 2 cents.
-
- object
- --
- -------------------------------------------------------------------------------
- jeff | "Dismiss whatever insults your own soul."
- kotula@cs.umn.edu | Walt Whitman
- -------------------------------------------------------------------------------
-