Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!zaphod.mps.ohio-state.edu!usc!ucsd!hub!eiffel!bertrand From: bertrand@eiffel.UUCP (Bertrand Meyer) Newsgroups: comp.lang.eiffel Subject: Re: Eiffel cleanup #1: The creation mechanism Keywords: Separate operation on references from operations on objects Message-ID: <235@eiffel.UUCP> Date: 21 Jan 90 01:46:51 GMT References: <226@eiffel.UUCP> <7862@cognos.UUCP> Organization: Interactive Software Engineering, Santa Barbara CA Lines: 81 In <7862@cognos.UUCP>, keithc@cognos.UUCP (Keith Campbell) suggests using creation expressions rather than creation instructions. For example the instructions [1] > x := !D!f(...) [2] x := !D! would assign to x the value of the right-hand side expressions, denoting a newly created object of type D, (after initializing this object through f in the case [1]). The advantage is that such an expression can also be used in contexts other than assignments, for example as actual argument to a routine. In keeping with my earlier note, Mr. Campbell would also accept one of [3] > x := !! [4] x := !!f (...) if the base class of x's type has no creation procedure. Forms [3] and [4], however, do not seem acceptable. The right-hand side is not a true expression since its meaning depends on the type of x, which does not even occur in that right-hand side. As Hoare pointed out in his ``Hints on Programming Language Design'' Stanford CS Report, 1973, reprinted in Ellis Horowitz's ``Programming Languages: A Grand Tour'', Computer Science Press, 1983), one of the pleasant properties of expressions is that an expression such as E + F can be understood solely in terms of its parts. Here this is clearly violated. Mr. Campbell's major argument, when applied to this case, provides further evidence of the same problem: obviously, forms [3] and [4] cannot be used as anonymous actual arguments, since by themselves the expressions are ambiguous (you cannot understand them without further information on their intended type). If we want to support anonymous creation expressions, then, the only solution is to accept forms [1] and [2] only: in other words, all creation operations must list the class. This comes very close to the Simula 67 convention with a different syntax: in Simula, object creation is obtained by writing expressions (not instructions) of the form new class_name (arguments) where the class_name is required. I considered this at the time of the original Eiffel design but rejected it for several reasons, including convenience. Most creation operations (perhaps 90% in my experience) are of form [3] or [4] and it seems to be a nuisance to require the programmer to repeat the type of x in every case. It is interesting to relate this to another suggestion that I just received through a private mail message. The author of that message suggested that the initializing routine should be required; in other words, forms [2] and [3] would not be supported. This is easy to achieve: we could just have a procedure ``nothing'' (which does what its name indicates) in class ANY. Then instead of an empty creation clause you would be required to write a clause of the form creation nothing if you want the class to have instances. But then if we combine this suggestion with what the above discussion indicates as the result of Mr. Campbell's suggestion, we have to write [5] x := !CLASS_NAME!nothing instead of just [6] x !! For creation instructions, a quite common occurrence in Eiffel software (at least for basic software components, such as libraries), I frankly prefer [6] to [5] and I think most programmers will agree. -- -- Bertrand Meyer bertrand@eiffel.com