On Wed, Jan 30, 2002 at 11:11:59AM +0100, Andre Poenitz wrote:

> On Wed, Jan 30, 2002 at 08:08:22AM +0200, Martin Vermeer wrote:
> > ...and feel free to explain what you mean... if this is clear to both of you,
> > to me it is Chinese ;-)
> 
> The 'InsetCode' stuff is (from a strict OO point of view at least - which I
> not always support) a bad thing.
> 
> An object should identify itself by its behaviour, not by providing some
> magic value and pushing the responsibility to 'get it right' to 'user code'.
> 
> The 'clean solution' would be to create some 
> 
>   virtual bool canBePutIntoALabel() const { return false; }
> 
> into the inset base class and override this by putting 
> 
>   virtual bool canBePutIntoALabel() const { return true; }
> 
> in the classes that 'have this property'. User code simply has to call
> 
>   inset->canBePutIntoALabel()
> 
> to learn whether this inset can be put in a label or not.
> 
> If religious reasons don't count much for you imagine what happens when
> we add a new inset that derives from and inset with canBePutIntoALabel() ==
> true.  With the InsetCode 'solution' you have to add the proper InsetCode
> to the if() in the user code, with the 'proper' solution you do not have to
> do anything. It just works.
> 
> Now you might argue that adding another case to the if() is not much work.
> Fair enough... But how do you tell which user code is affected without
> checking _each_ file manually? And what happens to your if-clauses if we
> have 30 insets? 
> 
> Andre'

Apropos of this discussion, I just had a look at lyxfunc.C, where there
is this huge switch at lines 563-661 that only seems to do this:
Find out what type of inset we have, assign the code value to 'code', 
and then at the end, test if anything has happened to 'code' so it is
no longer NO_CODE, and draw the consequences from that. No more.

Do I miss something? Or is there a reason why the local variable 'code'
is given any specific values? I don't see it used anywhere else.

If I am right this would be the place to start sanitizing :-)

- Martin

Attachment: msg32232/pgp00000.pgp
Description: PGP signature

Reply via email to