Re: time / update problem

Frederic Merizen <[email protected]> Thu, 14 Jul 2005 23:26:20 +0200
Newsgroups gmane.comp.lang.eiffel.smalleiffel
Message-ID <[email protected]>
Hello Raphael,

you 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.)