Re: time / update problem
Colnet Dominique <[email protected]> Fri, 15 Jul 2005 11:47:02 +0200
| Newsgroups | gmane.comp.lang.eiffel.smalleiffel |
|---|---|
| Message-ID | <[email protected]> |
Frederic Merizen wrote: >>Hello, >> >>what should the following code print? >> >>class MAIN >>creation >> make >>feature >> make is >> local >> now: TIME >> do >> create c.make >> now.update >> c.never.update -- is this ever executed??? >> io.put_string(c.never.elapsed_seconds(now).out + "%N") >> end >> c: CC >>end >> >>class >> CC >>creation >> make >>feature >> make is do end >> never: TIME >>end >> >>In my eyes it should be close to 0, but it seems that the line >>c.never.update is never done. Is this an invalid call for some reason or >>yet another optimizer bug? > > > TIME is an expanded class, so the qualified call 'c.never' returns a copy of > the attribute. The call to 'update' only updates the copy. > > I'd say there's a dessign lesson here: "think twice before creating mutable > expanded classes" (such as TIME - but I do not intend to specifically > criticize TIME here. There may well be good reasons for this choice in the > case of TIME - maybe a performance tradeoff. I don't know for sure, I wasn't > on the team yet when that class was written.) I think you are perfectly right: I made a mistake in TIME and we should remove all modifications procedures from class TIME. May be a strict simple rule about expanded classes would be to disallow all modification procedures ? Is this simple rule too strict ? If modification procedures remains allowed, I think we should add a new check in the compiler to avoid this terrible pitfall of user-defined expanded. Note for SmartEiffel developpers: a new visitor like the one we have for example to check exports could check that the expanded is not used for writing... if you see what I mean. Using the same idea, we should also check the code of all dispose routine to see if the disposed object is not passed away. Note for everybody: we won't change rules about user-expanded classes in release 2.2. (Stay cool.) -- -------------------------------------------------------------- [email protected] -- IUT (Nancy 2) -- INRIA Lorraine http://SmartEiffel.loria.fr -- The GNU Eiffel Compiler POST: Loria, B.P. 239,54506 Vandoeuvre les Nancy Cedex, FRANCE Voice:+33 0383913140 Mobile: +33 0665362381 Fax:+33 0383581701