Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!tut.cis.ohio-state.edu!seal.cis.ohio-state.edu!ogden From: ogden@seal.cis.ohio-state.edu (William F Ogden) Newsgroups: comp.lang.eiffel Subject: Re: Functions without side effects (was Old confusion) Message-ID: <131263@tut.cis.ohio-state.edu> Date: 6 Jun 91 23:05:03 GMT References: <1991Jun3.145924.28406@mstr.hgc.edu> <130242@tut.cis.ohio-state.edu> <1177@tetrauk.UUCP> Sender: news@tut.cis.ohio-state.edu Organization: The Ohio State University, Department of Computer and Information Science Lines: 34 In article <1177@tetrauk.UUCP> rick@tetrauk.UUCP (Rick Jones) writes: ... | Consequently operations like Top make poor | choices as primary operations, since their implementation inevitably ^^^^^^^^^^ | involves making a copy of a data structure entry. ... >You are presuming a system with value semantics. OO systems often work >very effectively with reference semantics (in Eiffel reference semantics are >the default unless you specify "expanded" variables or classes). In this case >the Top operation simply returns a pointer to the object on the top of the >stack, which is highly efficient. >In fact I would suggest that a system in which large objects are used is best >handled using reference semantics, otherwise there will be a lot of >inefficiencies elsewhere resulting from copying. The programmer must of course >be aware of this, and use "clone" operations where required. I guess I did presume it was obvious that the strange side effects which result from the aliasing inherent in general reference semantics violated the comprehensibility requirement for reusable software. As it turns out, referencs semantics are fine -- provided you only allow _one_ reference to each object. (With this constraint, you effectively have value semantics, of course.) Now the problem, rephrased in these terms, is that our small object bias leads us to design classes with operations like Top which create multiple references to the same object. One of the challenges of object oriented programming is still to design classes so that excess copying can be avoided or (if you insist on reference semantics) so that multiple references can be avoided. -- /Bill