Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: >this< as a reference Message-ID: <58304@microsoft.UUCP> Date: 17 Oct 90 17:54:19 GMT References: <11375@life.ai.mit.edu> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 32 >Now that there is no need to assign to >this<, wouldn't it have >been cleaner if >this< were a reference, and not a pointer ? I think so, but if one had made "this" a reference [in which case call it "self"] then one should have changed other parts of the language to return references too. For example, in that case "new" should return a reference rather than a pointer too. Then, if one is making use of references central in the language, one probably needs to make references assignable, like other OOP languages. Not using references for everything has given C++ some indirect advantages, though. Most other OOPLs always access objects via reference, using reference semantics. This hinders their ability to offer extended "primitive" classes such as class complex or String classes. The other languages thus also don't embed objects, but only embed a reference to the "embedded" object, leading to more fragmentation, longer construction times, additional indirections, etc. Most other OOPLs also don't allow objects on stack or static, but only on the heap. So, overall, I think the C++ approach has faired pretty well for the language, even if the duality of pointer/reference semantics everywhere leads to some confusion. One programming convention that one can consider to cut down on the confusion is to use pointers to refer to non-primitive objects -- things that follow "reference semantics", and use references for "primitive" objects -- things like complex and String that follow value semantics. To my mind, perhaps the saddest legacy left over from "C" days is the automatic conversion of an array to a pointer to its first member. Thus, when presented with a Foo*, one doesn't really know if one has access to an isolated Foo object, the start of an array of Foos, or a pointer into an array of Foos. To my mind this is a great weakness in the C++ type system, and leads to much aliasing problems, and compilers having to pessimize their code. Too late to fix it now, though....