home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!stanford.edu!EE.Stanford.EDU!sierra!mcgrant
- From: mcgrant@rascals.stanford.edu (Michael C. Grant)
- Subject: Re: the 'standard' complex class
- In-Reply-To: zougas@me.utoronto.ca's message of Thu, 27 Aug 1992 03:13:46 GMT
- Message-ID: <MCGRANT.92Aug26232210@rascals.stanford.edu>
- Sender: usenet@EE.Stanford.EDU (Usenet)
- Organization: Information Systems Laboratory, Stanford University
- References: <MCGRANT.92Aug26143400@rascals.stanford.edu> <BtMGyz.52A@me.utoronto.ca>
- Date: 26 Aug 92 23:22:10
- Lines: 44
-
- In article <BtMGyz.52A@me.utoronto.ca> zougas@me.utoronto.ca (Tom Zougas) writes:
-
- mcgrant@rascals.stanford.edu (Michael C. Grant) writes:
-
- >Because the class does not need to be specially notified when the .re or
- >.im fields change, why not make them public? It certainly allows for
- >maximum flexibility; it won't break a single function already written
- >for complex numbers.
-
- Don't forget that complex numbers could also be represented in polar form.
- The point of abstraction is you don't want to know HOW the class is
- represented only WHAT is available.
-
- I don't need that old tired line again. I understand the value of
- abstraction---of course that's true in general. But I have no desire
- whatsoever to have a complex ABSTRACT data type. I want a CONCRETE
- EFFICIENT data type. I want to know EXACTLY how the class is represented,
- because I can easily make design choices that way to improve efficiency.
- Despite the fact that even doubles are abstract data types, we really don't
- think of them as such. We can easily assign values to them, perform
- automatic type casts, etc. without worrying about which member function to
- use.
-
- If I wanted a polar class I could certainly whip one up with the
- appropriate conversions to the standard complex class and so forth. And,
- if it weren't for the fact that the angle probably ought to be represented
- in fixed-point, I'd make its data members public too---because setting
- the value of .r or .theta wouldn't trigger a chain reaction of events
- as often happens in abstract data types.
-
- Inlining access functions might give
- the efficiency you need.
-
- Nope, unfortunately that's not true---the way AT&T set things up, that is.
- Their functions pass by value and not by reference, and from examining the
- assembly I can tell you that the efficiency isn't there, even for the
- inlined functions. Of course, when I manually changed appropriate functions
- to accept 'const complex&' instead of 'complex', that improved things a
- lot, but not quite to the point that I'm happy with keeping .re and .im
- private.
-
- Michael C. Grant
-
-
-