Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!mcvax!hafro!krafla!snorri From: snorri@rhi.hi.is (Snorri Agnarsson) Newsgroups: comp.lang.c++ Subject: Re: Eiffel vs. C++ Message-ID: <1021@krafla.rhi.hi.is> Date: 9 Jun 89 11:19:28 GMT References: <77300029@p.cs.uiuc.edu> Organization: University of Iceland Lines: 95 From article <77300029@p.cs.uiuc.edu>, by johnson@p.cs.uiuc.edu: > >> Written 6:48 pm Jun 4, 1989 by bertrand@eiffel.com > Responses written by Ralph Johnson > >>Assertions > I think that assertions are one of the most attractive things about > Eiffel. I said this to a more theoretical member of my department, > and he made a snide remark, after which he pointed out that there are > many assertions one might want to make about programs that the Eiffel > assertion language will not let you make. This is a bogus argument! Well -- I agree with that argument. However I agree with you that assertions are good (at least they are better than nothing), but I think well formulated preconditions and postconditions, written as documentation, are necessary and sufficient. Assertions can serve as scaffolding for testing. >>Garbage collection > > This is both a major advantage and disadvantage. Would you advise > us writing our operating system in Eiffel instead of C++? What > impact does your garbage collector have on real-time software? In my opinion garbage collection is the single most useful feature of a programming language. Without garbage collection polymorphism is severely handicapped and programmers tend to shy away from clean designs because of the restrictions imposed by the lack of garbage collection. Consider the following C function: Usage: x:=plus(y,z); Precondition: y and z contain integers represented as zero terminated character strings of digits. Postcondition: x contains the sum of y and z, as a zero terminated character string of digits. If C had garbage collection we could write code such as: x=plus(x,plus(y,z)); ... y=x; Instead we have to write as follows: t1=plus(y,z); t2=x; x=plus(x,t1); free(t1); free(t2); /* assuming that the string pointed to by t2 is not pointed to by any other variable */ ... y=strcpy(x); /* unless you want to risk multiple pointers to the same string, in which case you would need to be VERY CAREFUL when freeing that string */ It is often said that garbage collection is too costly, but I suggest that in the above example the solution with garbage collection is probably more efficient, both in programmer effort AND in the speed of the resulting program. By the way, if garbage collection is too expensive, how about 'malloc' and 'free'? Do you think those routines are less expensive? Why do you think so? We should also consider the effort needed to document memory management issues for our (reusable) modules. If garbage collection is not available we get two bad effects: 1) The effort of designing a module for a given problem, PLUS the effort of documenting all the memory management issues needed to use the module is too great. Therefore you do not design or use modules. Or perhaps you use them without adequate documentation, leaving a can of worms for future maintainers. 2) You put a lot of effort into designing, coding and documenting modules, including all the memory management issues the user needs to know about to use the modules, so as not to get memory leaks or heap smashes. The design document for the modules become so huge and complicated that nobody uses the modules (or, perhaps, the modules are used, but incorrectly). In my opinion garbage collection is the single most useful feature of Prolog, LISP, SmallTalk, Eiffel, CLU, etc., etc. How many would use the above languages if they did not have garbage collection? In my opinion, very few. > Ralph Johnson >>Bertrand Meyer -- Snorri Agnarsson | Internet: snorri@rhi.hi.is Taeknigardur, Dunhaga 5 | UUCP: ..!mcvax!hafro!rhi!snorri IS-107 Reykjavik, ICELAND