[fpc-devel] Considerations about observer [was: Free Pascal 2.6.2 rc1]

luiz americo pereira camara luizmed at oi.com.br
Thu Nov 29 04:22:55 CET 2012


>>> On 2012-11-27 16:19, Michael Van Canneyt wrote:
>
>
> Correct. But the design should also not try to cover all possible use cases
> at any cost.
>
> Till now, I have not seen a common use case that will not work.

See Test1 in a separate message i sent. It will not work with the
current implementation


>> I just proposed a change that will give more flexibility for the
>> programmer when designing his application interface. As a plus with
>> less typecasts, so less overhead.
>
>
> If we assume for a second that the internal change to store the interface
> instead of the instance is done:
>
> There are not less typecasts executed, they are in a different place simply.
> You must always type the typecast before calling AttachObserver, I do it
> inside AttachObserver. My code is therefore simpler to read, generates less
> code and hence is preferable.

See Test2 in the message i sent. The same Obj is tested for
IFPObserver 7 times while would be one

>
>         movq    $_$PROGRAM$_Ld1,%rsi
>         movq    U_$P$PROGRAM_$$_C,%rdi
>         call    fpc_class_as_corbaintf
>         movq    %rax,%rdi
>         call    P$PROGRAM_$$_DOI$MYI
>
> This kind of code you will generate for each call to
> AttachObserver/DetachObserver.

Not necessarily.

Using GetInterface or Supports will avoid the direct typecast

Plus:

1) Currently if you don't know before hand if the object implements
IFPObserver (most cases), you will have to do the check in the caller
anyway
2) Like in Test1 (see other message) there'll be cases that no check
or typecast, by the caller or by the callee, will be done at all


> So, not requiring the interface to be passed on saves code if you use corba
> interfaces. Using COM classes would generate even more code for each
> invokation.
>
> Just to show why I prefer to avoid COM interfaces and the whole 'as' when
> possible.

Just to be clear: i'm not proposing to use COM interfaces

BTW: CORBA interfaces does not requires TGUID so you can remove:

  GUIDObserved : TGUID = BaseGUIDObserved;
  GUIDObserver : TGUID = BaseGUIDObserver;

> If it had been possible to implement the whole observer thing without using
> interfaces, I would have done it, but alas...

Yep. The first time i saw the generated code for interface i think:
"God: i will never use this". Today i use in selected cases.

Luiz



More information about the fpc-devel mailing list