Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2010-05

Interface delegation fix: backport to FPC 2.4.2 ...?

95 messages · 19 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

Is the following bugfix (original target was 2.4.0) going to make it into FPC 2.4.2?

I'm about to implement something in fpGUI and would really like to use the Observer pattern and interface delegation to attach the Observer function to existing classes. Without this fix, it's not possible.

http://bugs.freepascal.org/view.php?id=12778

@Michael van Canneyt
Have we come to a decision about Observer support in FPC base classes? This would obviously help what I am doing now as well - but I guess something like that will not make it into FPC 2.4.2 even if the answer is yes for Observer in base classes?

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Martin Schreiber
to Graeme Geldenhuys
Graeme Geldenhuys wrote 11 lines
Hi, Is the following bugfix (original target was 2.4.0) going to make it into FPC 2.4.2? I'm about to implement something in fpGUI and would really like to use the Observer pattern and interface delegation to attach the Observer function to existing classes. Without this fix, it's not possible. http://bugs.freepascal.org/view.php?id=12778

Maybe
http://bugs.freepascal.org/view.php?id=16365
must be fixed too until you can use interface delegation to a class?

Martin

Reply by email

Marco van de Voort
to Graeme Geldenhuys: Is the following bugfix (original target was 2.4.0) going to make it into FPC 2.4.2? I'm…

In our previous episode, Graeme Geldenhuys said:

Show quoted text 8 lines
Is the following bugfix (original target was 2.4.0) going to make it into FPC 2.4.2? I'm about to implement something in fpGUI and would really like to use the Observer pattern and interface delegation to attach the Observer function to existing classes. Without this fix, it's not possible. http://bugs.freepascal.org/view.php?id=12778

Did you verify that it works when you insert this fix into 2.4.1? Does it work with 2.5.1 currently?

Show quoted text 5 lines
@Michael van Canneyt Have we come to a decision about Observer support in FPC base classes? This would obviously help what I am doing now as well - but I guess something like that will not make it into FPC 2.4.2 even if the answer is yes for Observer in base classes?

I don't think making the current classes a patch work of styles is a good way to go. Today it is observers, tomorrow it is iterators etc.

Better follow the style of generics, and define an unit with base classes based on such patterns, without the fluff of other philosophies.

Reply by email

Graeme Geldenhuys
to Marco van de Voort

Marco van de Voort het geskryf:

Show quoted text 5 lines
> > http://bugs.freepascal.org/view.php?id=12778 Did you verify that it works when you insert this fix into 2.4.1? Does it work with 2.5.1 currently?

I haven't tried to port that fix to 2.4.1 myself. It does work in current 2.5.1 though - just tried. I am quickly putting together a very basic prototype implementation of what I eventually want to add to fpGUI. This will allow me to double check the delegation fix with more certainty (oh how we long for unit tests covering all these features).

I don't think making the current classes a patch work of styles is a good way to go. Today it is observers, tomorrow it is iterators etc.

Observer has been around for ages, it's not a "today's flavour" feature. It's minimal addition with huge benefits. This was discussed off the mailing list by Michael, Joost and myself. Consensus was positive, but I just want to confirm the final answer. Also, it will not break anything, because observer functionality did not exist before in the base classes.

As for the iterators idea I mentioned months ago. I decided to keep it as a separate unit and used by my projects as needed. This way I don't need to fight FPC policies/ideals if I want to make changes. [it's not always beneficial to contribute code]

The Observer pattern is a lot simpler and would not change in the future.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Martin Schreiber: Maybe http://bugs.freepascal.org/view.php?id=16365 must be fixed too until you can use…

Martin Schreiber het geskryf:

Maybe http://bugs.freepascal.org/view.php?id=16365 must be fixed too until you can use interface delegation to a class?

That seems to be a bug only in COM interfaces. I want to use Corba interfaces which do not AV.

The same example as the one in the bug report, but with Corba interfaces enabled. No AV with current 2.5.1

-----------[ delegation.pas ]---------------------
program delegation;
{$ifdef FPC}
  {$mode objfpc}{$h+}
  {$interfaces corba}
{$endif}
uses
 sysutils;
type
 itest = interface
  procedure test;
 end;
 timpclass = class(tobject,itest)
 private
   procedure test;
 end;
 ttestclass = class(tobject,itest)
  private
   fimp: timpclass;
   property imp: timpclass read fimp implements itest;
  public
   constructor create;
   destructor destroy; override;
 end;

{ timpclass }

procedure timpclass.test;
begin
 writeln('test');
end;

{ ttestclass }

constructor ttestclass.create;
begin
 fimp:= timpclass.create;
end;
destructor ttestclass.destroy;
begin
 inherited;
 fimp.free;
end;
var
 testclass: ttestclass;
begin
 testclass:= ttestclass.create;
 itest(testclass).test; //<<<<---- No more AV!
 testclass.free;
end.

--------------------------------

Here is the output I get under Ubuntu 8.04.3 (64-bit).

$ /opt/fpc_2.5.1/x86_64-linux/bin/ppcx64 delegation.pas Free Pascal Compiler version 2.5.1 [2010/05/14] for x86_64 Copyright (c) 1993-2009 by Florian Klaempfl
tmp $ ./delegation
test
tmp $

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Marco van de Voort
to Graeme Geldenhuys: Marco van de Voort het geskryf: I haven't tried to port that fix to 2.4.1 myself. It does…

In our previous episode, Graeme Geldenhuys said:

> way to go. Today it is observers, tomorrow it is iterators etc. Observer has been around for ages, it's not a "today's flavour" feature. It's minimal addition with huge benefits.

So are iterators and umpteen other patterns. (like e.g. using interfaces Java style to categorize the various container types)

This was discussed off the mailing list by Michael, Joost and myself. Consensus was positive, but I just want to confirm the final answer.

I'm against. This is a sliding slope. Michael agreeing to this surprises me a bit. He was not exactly fond of when notifiers were introduced in Delphi's containertypes (which are more or less observer relations too, though less flexible)

As for the iterators idea I mentioned months ago. I decided to keep it as a separate unit and used by my projects as needed. This way I don't need to fight FPC policies/ideals if I want to make changes. [it's not always beneficial to contribute code]

It is not always beneficial to incorporate all patches either.

The Observer pattern is a lot simpler and would not change in the future.

Most patterns are pretty much unchanged in principle since GoF.

Reply by email

Graeme Geldenhuys
to Marco van de Voort

Marco van de Voort het geskryf:

I'm against. This is a sliding slope. Michael agreeing to this surprises me a bit.

Michael was the one that suggested it to Joost and myself. :) The usage of Observer in base classes might even completely eliminate the need for DB-aware components.

After I implemented the initial Model-GUI-Mediator (MGM) in tiOPF I came to realize how handy the Observer really is. Michael helped extend MGM and the benefits become even more. I'm implementing Actions support in fpGUI now and again using the Observer pattern. So far this totally eliminates the need for TBasicActionLink and descendants - reducing the notifications system between action and clients to mere 10-15 lines of code. That's a huge reduction compared to the code in VCL or LCL to do similar functionality.

Anyway, this discussion is now totally off-topic. Interface delegation seems to work very nice with Corba Interfaces by the way. No issues found so far.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Marco van de Voort
to Graeme Geldenhuys

In our previous episode, Graeme Geldenhuys said:

Show quoted text 10 lines
Marco van de Voort het geskryf: > > I'm against. This is a sliding slope. Michael agreeing to this surprises me > a bit. Michael was the one that suggested it to Joost and myself. :) The usage of Observer in base classes might even completely eliminate the need for DB-aware components. system between action and clients to mere 10-15 lines of code. That's a huge reduction compared to the code in VCL or LCL to do similar functionality.

Note that I was mainly talking about any object types that are designed to be Delphi compatible. The extra properties and methods polute the namespace, and could get in the way of users own similar systems.

I don't care about such schemes being used in code that is not Delphi compat (fpgui, fpweb etc). I wouldn't like it for the database components or LCL components though.

Reply by email

Michael Van Canneyt
to Marco van de Voort
Marco van de Voort wrote 19 lines
In our previous episode, Graeme Geldenhuys said: > Marco van de Voort het geskryf: >> >> I'm against. This is a sliding slope. Michael agreeing to this surprises me >> a bit. > > Michael was the one that suggested it to Joost and myself. :) The usage of > Observer in base classes might even completely eliminate the need for > DB-aware components. > system between action and clients to mere 10-15 lines of code. That's a > huge reduction compared to the code in VCL or LCL to do similar functionality. Note that I was mainly talking about any object types that are designed to be Delphi compatible. The extra properties and methods polute the namespace, and could get in the way of users own similar systems. I don't care about such schemes being used in code that is not Delphi compat (fpgui, fpweb etc). I wouldn't like it for the database components or LCL components though.

The problem is that this pretty much rules out the use of the observer pattern, because you need to subclass every existing class that you want to work with, which is exactly the problem that we're trying to solve in the first place. To be effective, it needs to be in the base classes.

I have an implementation in place, which doesn't affect too much the existing classes: it adds 1 public property and one private method; There is no impact on code efficiency.

I am all for systems to reduce namespace pollution and minimalizing impact for the users, but maintaining the status quo forever is also not an option.

Michael.

Reply by email

Graeme Geldenhuys
to Marco van de Voort: In our previous episode, Graeme Geldenhuys said: Note that I was mainly talking about any…

Marco van de Voort het geskryf:

Note that I was mainly talking about any object types that are designed to be Delphi compatible.

Like I said, they will not interfere with Delphi compatibility at all because Delphi doesn't have such a feature. [yet many other toolkits/frameworks do] The usage of a GUID identifying the interface will also reduce conflicts with somebody else's code - but considering that 'interface delegation' was not implemented till a few days ago, that will also reduce any possible issue. I don't know if FPC supports Interface Method Resolution, but that is also a specific language feature introduced by Borland to overcome interface conflicts.

I really don't see a the problem here. FPC often implements things that have far greater chances of breaking existing code - I just pointed out another such example a few days ago.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Jonas Maebe
to Graeme Geldenhuys
Graeme Geldenhuys wrote 5 lines
I really don't see a the problem here. FPC often implements things that have far greater chances of breaking existing code - I just pointed out another such example a few days ago.

I don't have an opinion on the current discussion, but you are comparing apples to oranges here. This discussion is about extending base classes of the RTL. The other discussion was about a fix for a bug in the typing system of the compiler (a bug that simply had to be fixed to make the language's typing system sound again).

Jonas

Reply by email

Joost van der Sluis
to Graeme Geldenhuys: Marco van de Voort het geskryf: Like I said, they will not interfere with Delphi…
Graeme Geldenhuys wrote 8 lines
Marco van de Voort het geskryf: > > Note that I was mainly talking about any object types that are designed to > be Delphi compatible. I really don't see a the problem here. FPC often implements things that have far greater chances of breaking existing code - I just pointed out another such example a few days ago.

That wasn't a new feature, but a bug-fix. Which was abused (used without seeing the consequences) a lot.

Joost.

Reply by email

Graeme Geldenhuys
to Joost van der Sluis

Joost van der Sluis het geskryf:

That wasn't a new feature, but a bug-fix. Which was abused (used without seeing the consequences) a lot.

Well as far as I know it never worked, so I cannot see how it could every have been called implemented/completed. That "bug-fix" actually made it work, and for the first time as far as I know (at least for the last 5 years as that is how long I have been using FPC).

When I started tinkering with FPC I tried to port one of my Delphi apps as part of the learning process. Interface 'implements' was one of things that did not work then already.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Marco van de Voort
to Michael Van Canneyt: The problem is that this pretty much rules out the use of the observer pattern, because…

In our previous episode, Michael Van Canneyt said:

Show quoted text 8 lines
> I don't care about such schemes being used in code that is not Delphi compat > (fpgui, fpweb etc). I wouldn't like it for the database components or LCL > components though. The problem is that this pretty much rules out the use of the observer pattern, because you need to subclass every existing class that you want to work with, which is exactly the problem that we're trying to solve in the first place. To be effective, it needs to be in the base classes.

Yes, so it should IMHO be kept outside the current hierarchy, but using a new hierachy with a new baseclass (only one level higher than object) Those are hopeless outdates anyway, and adding even more paradigms to them is no solution.

I have an implementation in place, which doesn't affect too much the existing classes: it adds 1 public property and one private method; There is no impact on code efficiency.

Sure. Today this, tomorrow that. I still think this is a bad idea.

I am all for systems to reduce namespace pollution and minimalizing impact for the users, but maintaining the status quo forever is also not an option.

System quo what where? The current libs are mainly about compatibility, and because of that e.g. many language extensions from D4+ were never introduced into the system (which is why e.g. the LCL uses TStrings instead of a minimal interface needed to draw)

Ducktaping more on top of this is IMHO the worst of both worlds. Old stuff out of compatiiblity, but not entirely.

If the status quo hurts so much, than start with a clean slate.

Reply by email

Joost van der Sluis
to Graeme Geldenhuys: Joost van der Sluis het geskryf: Well as far as I know it never worked, so I cannot see…
Graeme Geldenhuys wrote 13 lines
Joost van der Sluis het geskryf: > > That wasn't a new feature, but a bug-fix. Which was abused (used without > seeing the consequences) a lot. Well as far as I know it never worked, so I cannot see how it could every have been called implemented/completed. That "bug-fix" actually made it work, and for the first time as far as I know (at least for the last 5 years as that is how long I have been using FPC). When I started tinkering with FPC I tried to port one of my Delphi apps as part of the learning process. Interface 'implements' was one of things that did not work then already.

We're talking about different things. what we were discussing was the addition of the ability to use the observer pattern to the rtl base classes. The change from a few days ago you were referring to which was fixed was the matching-parameters change.

Those are not comparable.

Joost.

Reply by email

Joost van der Sluis
to Marco van de Voort: In our previous episode, Michael Van Canneyt said: Yes, so it should IMHO be kept outside…
Marco van de Voort wrote 28 lines
In our previous episode, Michael Van Canneyt said: > > I don't care about such schemes being used in code that is not Delphi compat > > (fpgui, fpweb etc). I wouldn't like it for the database components or LCL > > components though. > > The problem is that this pretty much rules out the use of the observer > pattern, because you need to subclass every existing class that you want > to work with, which is exactly the problem that we're trying to solve in > the first place. To be effective, it needs to be in the base classes. Yes, so it should IMHO be kept outside the current hierarchy, but using a new hierachy with a new baseclass (only one level higher than object) Those are hopeless outdates anyway, and adding even more paradigms to them is no solution. > I have an implementation in place, which doesn't affect too much the > existing classes: it adds 1 public property and one private method; > There is no impact on code efficiency. Sure. Today this, tomorrow that. I still think this is a bad idea. > I am all for systems to reduce namespace pollution and minimalizing impact > for the users, but maintaining the status quo forever is also not an option. System quo what where? The current libs are mainly about compatibility, and because of that e.g. many language extensions from D4+ were never introduced into the system (which is why e.g. the LCL uses TStrings instead of a minimal interface needed to draw)

I think I would agree with you if it was true that most libraries are about compatibility. But if I want to replace
TComponent/TControl/TPersistent with newer versions, I would start copy-pasting them. And there would be only a few changes. (I can't think of any now, expect for adding the ability to use the observer pattern)

Joost.

Reply by email

Graeme Geldenhuys
to Marco van de Voort: In our previous episode, Michael Van Canneyt said: Yes, so it should IMHO be kept outside…

Marco van de Voort het geskryf:

System quo what where? The current libs are mainly about compatibility, and because of that e.g. many language extensions from D4+ were never introduced

You are totally over exaggerating. If FPC's only design goal is to be compatible with Delphi, there is NO future for FPC. Surely FPC should be open to new features and ideas to improve itself over competition - yet keeping compatibility in mind but not limiting itself to the latter.

As for not many language extensions... Developers here are constantly told it is simply because nobody is supplying patches for them. So what is it?

The Observer will NOT break any compatibility, has minimal impact on code size or the class interface.

tiOPF went through the same process a couple of years ago. Everybody made a big mountain of a problem about introducing Observer into one of it's most used base classes. In the end it was implemented and 3 years down the line, not a single person has every complained about it! In fact, more people started using the Observer feature for other things and commented on how handy it is. In tiOPF the internal list used by the Observer is only created when needed, so hardly any extra memory was used - and yes my programs loads about 50,000-80,000 objects and it did not affect our H.'s software loads even more objects and he never complained either.

If the status quo hurts so much, than start with a clean slate.

Starting a brand new class hierarchy is totally out of the question - that would be like rewriting the whole RTL and FCL! To quote the famous Florian saying: "you have no clue what you are talking about".

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Marco van de Voort
to Joost van der Sluis: I think I would agree with you if it was true that most libraries are about…

In our previous episode, Joost van der Sluis said:

Show quoted text 7 lines
> System quo what where? The current libs are mainly about compatibility, and > because of that e.g. many language extensions from D4+ were never introduced > into the system (which is why e.g. the LCL uses TStrings instead of a > minimal interface needed to draw) I think I would agree with you if it was true that most libraries are about compatibility.

If not, why are we having this discussion about FPC specific enhancements only 13 years after their introduction? (well, save for TFPList then)

Of course they are about compatibility. There is nothing else.

But if I want to replace TComponent/TControl/TPersistent with newer versions, I would start copy-pasting them.

I don't see why the observer pattern is needed at such low level any more than 20 other little handy features that each would be a lot easier if they just had a field/property in the baseclasses.

It is the beginning of the end.

And there would be only a few changes. (I can't think of any now, expect for adding the ability to use the observer pattern)

It is always only a few places. But what you are effectively doing is opening the gate.

If we allow this, the rest is only a matter of time. If you want to be the library designer, do so, and do it well instead of applying bandaids to the current classes.

Reply by email

Graeme Geldenhuys
to Marco van de Voort
Marco van de Voort wrote
I don't see why the observer pattern is needed at such low level any more than 20 other little handy features that each would be a lot easier if they just had a field/property in the baseclasses.

Marco, not trying to be rude, but please take a step back, see the big picture and listen to yourself. You sound totally ridiculous - it's to the point of being funny.

I don't know what software, if any, you write for a living but clearly other developers here see a benefit of "enhancing" the base classes. I can easily list a arms length of benefits in having the observer available in base classes. Just look at Java too see how popular the Observer can be. I'm pretty confident .NET would be similar. You seem to have a bit of tunnel vision - not seeing the big picture.

It is the beginning of the end.

Oh I get it! So do you want to be the person to tell Borland/Embarcadero that they should rather have re-implemented the whole RTL and created a totally separate hierarchy when they introduced a few new properties in the TObject recently. Because Marco doesn't agree with making low-level changes even if it means improvements down the line.

Oh, and should I mention that their "little" change, which was implemented in FPC for compatibility reasons, broke our company's application, fpGUI toolkit and caused problems in the tiOPF framework. That's just three projects I know of - I wonder how many other projects broke because of that. Yes if though our applications couldn't compile any more, it was a small thing to fix.

The Observer we would like to introduce should have little impact as well, and IF issues occur in developers own software, it should be easy to fix, or they can remove their Observer implementation and use the one that is included as standard in the FPC's RTL.

It is always only a few places. But what you are effectively doing is opening the gate. If we allow this, the rest is only a matter of time.

Oh, we are getting very dramatic now. :)

If you want to be the library designer, do so, and do it well instead of applying bandaids to the current classes.

And if you want to be a "compatibility freak" you are free to start your own fork of FPC - nobody is stopping you. Or simply switch to Delphi and be done with it.

We are trying to improve FPC!! Just like Borland/Embarcadero improved Delphi by introducing COM/Interface somewhere between D2 and D4, Actions in D4, Frame in D5, language extensions (unicode etc) in D2009 etc... They did that all without creating a totally new RTL hierarchy even if it mean breaking some old code.

Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt: The problem is that this pretty much rules out the use of the observer pattern, because…
Michael Van Canneyt wrote
I have an implementation in place, which doesn't affect too much the existing classes: it adds 1 public property and one private method; There is no impact on code efficiency.

Michael, I have two options to solve this:

1) Ignore Marco and implement it any way. I think you have just as much say as Macro on what goes into the FPC.

2) Do something similar to what we did with tiOPF and Interfaces support. Implement Observer in the base classes. IFDEF its functionality (this should pretty much cover one line of code only). Enable the IFDEF by default. That way everybody else can benefit from the new Observer support by default. Marco can then disable the IFDEF in his own copy of FPC and live in compatibility world (population 1).

Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Michael Van Canneyt
to Joost van der Sluis: I think I would agree with you if it was true that most libraries are about…
Joost van der Sluis wrote 35 lines
On Wed, 2010-05-19 at 16:59 +0200, Marco van de Voort wrote: > In our previous episode, Michael Van Canneyt said: >>> I don't care about such schemes being used in code that is not Delphi compat >>> (fpgui, fpweb etc). I wouldn't like it for the database components or LCL >>> components though. >> >> The problem is that this pretty much rules out the use of the observer >> pattern, because you need to subclass every existing class that you want >> to work with, which is exactly the problem that we're trying to solve in >> the first place. To be effective, it needs to be in the base classes. > > Yes, so it should IMHO be kept outside the current hierarchy, but using a > new hierachy with a new baseclass (only one level higher than object) Those are > hopeless outdates anyway, and adding even more paradigms to them is no > solution. > >> I have an implementation in place, which doesn't affect too much the >> existing classes: it adds 1 public property and one private method; >> There is no impact on code efficiency. > > Sure. Today this, tomorrow that. I still think this is a bad idea. > >> I am all for systems to reduce namespace pollution and minimalizing impact >> for the users, but maintaining the status quo forever is also not an option. > > System quo what where? The current libs are mainly about compatibility, and > because of that e.g. many language extensions from D4+ were never introduced > into the system (which is why e.g. the LCL uses TStrings instead of a > minimal interface needed to draw) I think I would agree with you if it was true that most libraries are about compatibility. But if I want to replace TComponent/TControl/TPersistent with newer versions, I would start copy-pasting them. And there would be only a few changes. (I can't think of any now, expect for adding the ability to use the observer pattern)

And, you would end up copying the whole FCL, LCL: one without observer support, one with it. It is obvious that this is not the idea.

Suppose I create a TStrings clone with observer support, it is useless: the whole FCL and LCL use TStrings from classes. So in effect, my implementation is sterile, since I cannot use it in any real situation that I actually need and why I implemented observer in the first place: to be able to observe for instance the changes in TMemo.Lines or TCombobox.Items. (and these are from real-world examples).

I agree that we must make sure all code that worked still works, so the interface names and their calls should have some FPC specific prefix. "fpo" or so;

But as for the location for this implementation there is no alternative but to implement it in Classes, and, more specific, in TPersistent.

There have been other changes/enhancements in the Classes unit that are not delphi compatible, but which have never broken other code. No-one objected then, I see no reason why this minor change is so questionable. I think the benefits of the observer pattern in the classes unit outweigh the 'incompatibility' issues.

One could adopt the same stance for the Sysutils code, or, for one, on the unix units. No-one ever did, and with good reason: there must be progress in FPC; we don't want to keep running behind Delphi forever. Compatibility: absolutely. But also: progress and enhancements !

Michael.

Reply by email

Bee Jay
to Michael Van Canneyt
Michael Van Canneyt wrote
there must be progress in FPC; we don't want to keep running behind Delphi forever. Compatibility: absolutely. But also: progress and enhancements !

Just to give some supports... I'm with Michael and Graeme here. I don't know about the others, but I for sure migrated totally to FPC/Lazarus since a few years ago because I need something that is BETTER than Delphi. Marco's argument seems to contradict with FPC/Lazarus spirit that it's not a simply Delphi clone.

If FPC/Lazarus does really want to be crazily fully 100% compatible with Delphi then where is the progress of dynamic package (BPL) support? It has been requested since a few years back by lots of people, yet almost none is done. Why language enhancements introduced in newer Delphi such as strict private, etc comes so late? Where is the support for dot character for unit name? Just to mention some incompatibilities, even with older Delphi.

Somehow it looks funny to me. When someone requests for new feature that is compatible with newer Delphi, FPC/Lazarus developer would say that FPC/Lazarus is not a Delphi clone. One should not hope every feature of Delphi would be available in FPC/Lazarus. Yet, if someone requests for enhancement that is not compatible with Delphi, FPC/Lazarus developer would say that FPC/Lazarus should maintain the compatibility with Delphi. Heh?! :P

I prefer to put enhancement as the first priority then compatibility (with Delphi) as the second. Compatibility with Delphi is good and always be welcomed, but that doesn't mean FPC/Lazarus should always be under the shadow of Delphi. Delphi's future is not as bright as yesterday. What is gonna happen to FPC/Lazarus if someday Delphi is abandoned by the author? Will us let FPC/Lazarus stuck in the middle of nowhere for the sake of compatibility?

-Bee-

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt: And, you would end up copying the whole FCL, LCL: one without observer support, one with…
Michael Van Canneyt wrote
that I actually need and why I implemented observer in the first place: to be able to observe for instance the changes in TMemo.Lines or TCombobox.Items. (and these are from real-world examples).

And my prototype implementation of TActions support in fpGUI using Observer is another example. I totally eliminated the TBasicActionLink class hierarchy yet have the same functionality as LCL/VCL Actions with less (and clearer) code.

No-one objected then, I see no reason why this minor change is so questionable.

I think Marco makes it his mission in life to disagree with everything I say. :-(

be progress in FPC; we don't want to keep running behind Delphi forever. Compatibility: absolutely. But also: progress and enhancements !

+1

Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Marco van de Voort
to Graeme Geldenhuys: Marco, not trying to be rude, but please take a step back, see the big picture and listen…

In our previous episode, Graeme Geldenhuys said:

Show quoted text 7 lines
> I don't see why the observer pattern is needed at such low level any more > than 20 other little handy features that each would be a lot easier if they > just had a field/property in the baseclasses. Marco, not trying to be rude, but please take a step back, see the big picture and listen to yourself. You sound totally ridiculous - it's to the point of being funny.

I'm sorry, but something that starts like this isn't worth commenting on.

Reply by email

Marco van de Voort
to Michael Van Canneyt: And, you would end up copying the whole FCL, LCL: one without observer support, one with…

In our previous episode, Michael Van Canneyt said:

Show quoted text 7 lines
> about compatibility. But if I want to replace > TComponent/TControl/TPersistent with newer versions, I would start > copy-pasting them. And there would be only a few changes. (I can't think > of any now, expect for adding the ability to use the observer pattern) And, you would end up copying the whole FCL, LCL: one without observer support, one with it. It is obvious that this is not the idea.

You would duplicate it, but not copy it. If you abandon compatibility, do it right.

Suppose I create a TStrings clone with observer support, it is useless: the whole FCL and LCL use TStrings from classes

I know the tradeoff yes. But a bandaid like FPC only solution does not solve anything either AND has compatibility issues.

So in effect, my implementation is sterile, since I cannot use it in any real situation that I actually need and why I implemented observer in the first place: to be able to observe for instance the changes in TMemo.Lines or TCombobox.Items. (and these are from real-world examples).

Yes. And the next person wants to iterate over tstrings with an iterator, or let them also support IEnumerable and IVector, and therefore let it inherit from TInterfaceobject (that's the thing that I would copy from Java btw, don't care about observer pattern).

I also assume there is not a lot of code inserted in nearly every method to detect change and call the observers too? Not all modifications are about interface changes :-)

I agree that we must make sure all code that worked still works, so the interface names and their calls should have some FPC specific prefix. "fpo" or so;

While that solves at least the worst compatibility issues. I still think it is a weak and redundant attempt.

If the current situation is so horribly dire that you can't really do without it, such a bandaid is not enough.

IMHO this is some not terribly thought through bandaid to fix some accute problem, and that sets a bad precedent.

But as for the location for this implementation there is no alternative but to implement it in Classes, and, more specific, in TPersistent.

The alternative is to reconsider the need for this.

There have been other changes/enhancements in the Classes unit that are not delphi compatible, but which have never broken other code.

Those were minor enhancements. Not support for new concepts.

so questionable. I think the benefits of the observer pattern in the classes unit outweigh the 'incompatibility' issues.

I don't think there are any benefits to making those classes even more complicated then they already are.

One could adopt the same stance for the Sysutils code, or, for one, on the unix units. No-one ever did, and with good reason: there must be progress in FPC; we don't want to keep running behind Delphi forever.

I do not really have the feeling this is a grand move forward. It sounds more like scratching some acute itch, rushed to be in the codebase before anybody notices.

Reply by email

Matt Emson
to Graeme Geldenhuys: Marco, not trying to be rude, but please take a step back, see the big picture and listen…

Sent from my iPhone

Graeme Geldenhuys wrote 11 lines
On 19 May 2010 17:36, Marco van de Voort wrote: > > I don't see why the observer pattern is needed at such low level > any more > than 20 other little handy features that each would be a lot easier > if they > just had a field/property in the baseclasses. Marco, not trying to be rude, but please take a step back, see the big picture and listen to yourself. You sound totally ridiculous - it's to the point of being funny.

I don't think so. I'd hate to see any specific pattern being implemented at a base level. Why? Exactly what Marco said. Patterns are faddy - you are not going to please everyone. I'd rather see a mechanism for injecting first class extensions to existing classes. That way, it really doesn't matter what pattern is implemented where. That would be far more worthwhile IMO.

M

Reply by email

Matt Emson
to Graeme Geldenhuys: Michael, I have two options to solve this: 1) Ignore Marco and implement it any way. I…

Sent from my iPhone

Graeme Geldenhuys wrote 7 lines
Michael, I have two options to solve this: 1) Ignore Marco and implement it any way. I think you have just as much say as Macro on what goes into the FPC. 2) Do something similar to what we did with tiOPF and Interfaces support.....

3) Quit whining, fork FPC and have done with it. Go be unhappy some place else?

Respect is a two way street, man, and IMO your attitude stinks.

Reply by email

Vincent Snijders
to Graeme Geldenhuys: Is the following bugfix (original target was 2.4.0) going to make it into FPC 2.4.2? I'm…
Graeme Geldenhuys wrote 6 lines
@Michael van Canneyt Have we come to a decision about Observer support in FPC base classes? This would obviously help what I am doing now as well - but I guess something like that will not make it into FPC 2.4.2 even if the answer is yes for Observer in base classes?

Is there a patch to review, so I can see what this discussion is all about? I wonder if something like class helpers is able to solve this, like Matt suggested. It would be useful for other things, not yet possible ...

Vincent

Reply by email

Sergei Gorelkin
to Matt Emson: Sent from my iPhone On 19 May 2010, at 17:52, Graeme Geldenhuys I don't think so. I'd…
Matt Emson wrote 8 lines
I don't think so. I'd hate to see any specific pattern being implemented at a base level. Why? Exactly what Marco said. Patterns are faddy - you are not going to please everyone. I'd rather see a mechanism for injecting first class extensions to existing classes. That way, it really doesn't matter what pattern is implemented where. That would be far more worthwhile IMO.

I couldn't have said it better than that.
I'd also vote for a mechanism allowing to attach an arbitrary property to a class instance, something like what e.g. GObject does. It is of course much harder to design and implement than a couple-line patch...

Regards,
Sergei

Reply by email

Nikolai Zhubr
to Sergei Gorelkin

19.05.2010 23:56, Sergei Gorelkin:

Show quoted text 12 lines
Matt Emson wrote: > > I don't think so. I'd hate to see any specific pattern being > implemented at a base level. Why? Exactly what Marco said. Patterns > are faddy - you are not going to please everyone. I'd rather see a > mechanism for injecting first class extensions to existing classes. > That way, it really doesn't matter what pattern is implemented where. > That would be far more worthwhile IMO. > I couldn't have said it better than that. I'd also vote for a mechanism allowing to attach an arbitrary property to a class instance,

Yes! Me too! :)

Nikolai

Show quoted text 9 lines
something like what e.g. GObject does. It is of course much harder to design and implement than a couple-line patch... Regards, Sergei _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Inoussa OUEDRAOGO
to Matt Emson: Sent from my iPhone On 19 May 2010, at 17:52, Graeme Geldenhuys I don't think so. I'd…
Matt Emson wrote 16 lines
Sent from my iPhone On 19 May 2010, at 17:52, Graeme Geldenhuys wrote: > On 19 May 2010 17:36, Marco van de Voort wrote: >> >> I don't see why the observer pattern is needed at such low level any more >> than 20 other little handy features that each would be a lot easier if they >> just had a field/property in the baseclasses. > > Marco, not trying to be rude, but please take a step back, see the big > picture and listen to yourself. You sound totally ridiculous - it's to the point of being funny. I don't think so. I'd hate to see any specific pattern being implemented at a base level. Why? Exactly what Marco said. Patterns are faddy - you are not going to please everyone. I'd rather see a mechanism for injecting first class extensions to existing classes. That way, it really doesn't matter what pattern is implemented where. That would be far more worthwhile IMO.

Agreed. This mechanism exists in Delphi and is called "class helper", see http://docwiki.embarcadero.com/RADStudio/en/Class_and_Record_Helpers See some samples :
* What are good uses for class helpers? at
http://stackoverflow.com/questions/253399/what-are-good-uses-for-class-helpers
* class helper to add for … in support for TComponent.Components / ComponentCount at
http://wiert.wordpress.com/2009/05/07/delphi-class-helper-to-add-for-%E2%80%A6-in-support-for-tcomponentcomponentscomponentcount/
* and New Delphi language features since Delphi 7 at http://edn.embarcadero.com/article/34324

Best regards.

Inoussa O.

Reply by email

Marco van de Voort
to Vincent Snijders: Is there a patch to review, so I can see what this discussion is all about? I wonder if…

In our previous episode, Vincent Snijders said:

Show quoted text 10 lines
> @Michael van Canneyt > Have we come to a decision about Observer support in FPC base classes? > This would obviously help what I am doing now as well - but I guess > something like that will not make it into FPC 2.4.2 even if the answer is > yes for Observer in base classes? Is there a patch to review, so I can see what this discussion is all about? I wonder if something like class helpers is able to solve this, like Matt suggested. It would be useful for other things, not yet possible ...

I'm maybe confused myself. I was thinking about Observable, not Observer.

That at least mitigate having to monitor state (in every method that changes the state of the object) and also keeps no state (the list is also in Observable)

Reply by email

Michael Van Canneyt
to Marco van de Voort: In our previous episode, Michael Van Canneyt said: You would duplicate it, but not copy…
Marco van de Voort wrote 8 lines
While that solves at least the worst compatibility issues. I still think it is a weak and redundant attempt. If the current situation is so horribly dire that you can't really do without it, such a bandaid is not enough. IMHO this is some not terribly thought through bandaid to fix some accute problem, and that sets a bad precedent.

Aha, but you are very wrong there.

The germs of this particular idea have been discussed 10 years ago, when fpGUI was first designed, with Sebastian Guenther, when Lazarus didn't even exist yet. I mentioned this to Joost and Graeme.

It is only now, after having worked on it in tiOPF and gaining the necessary experience and - equally important - having some compiler bugs fixed, that I think it becomes feasible to make an implementation that
a) Is universally usable.
b) has low-level impact on existing code.

But I can see we are getting nowhere like this.

I do not consider breaking down other people's proposals without offering a viable alternatives as a constructive discussion.

So - let's try another approach which may prove more constructive:

What are your proposals to get some kind of observer pattern implemented so it can be applied consequently throughout the classes of the FCL and LCL, without duplicating all code or subclassing all existing classes ?

I am not interested in the actual implementation of the observer pattern, just the means by which you think we can 'inject' one.

Please don't bother questioning the need/desirability of this feature, consider it a given.

Michael.

Reply by email

Michael Van Canneyt
to Marco van de Voort: In our previous episode, Vincent Snijders said: I'm maybe confused myself. I was thinking…
Marco van de Voort wrote 17 lines
In our previous episode, Vincent Snijders said: >> @Michael van Canneyt >> Have we come to a decision about Observer support in FPC base classes? >> This would obviously help what I am doing now as well - but I guess >> something like that will not make it into FPC 2.4.2 even if the answer is >> yes for Observer in base classes? > > Is there a patch to review, so I can see what this discussion is all > about? I wonder if something like class helpers is able to solve this, > like Matt suggested. It would be useful for other things, not yet > possible ... I'm maybe confused myself. I was thinking about Observable, not Observer. That at least mitigate having to monitor state (in every method that changes the state of the object) and also keeps no state (the list is also in Observable)

Observable and Observer go hand in hand. We're talking about both. Specifically, I want to add observable to TPersistent.

And yes, I have an implementation, it's currently outside the classes unit, but the whole point is to insert it into Classes.

Michael.

Reply by email

Graeme Geldenhuys
to Inoussa OUEDRAOGO: Agreed. This mechanism exists in Delphi and is called "class helper",…
Inoussa OUEDRAOGO wrote
Agreed. This mechanism exists in Delphi and is called "class helper", see http://docwiki.embarcadero.com/RADStudio/en/Class_and_Record_Helpers

Ah yes, the famous "class helper" which makes designing a class structure way more complex because their is no real structure|design - lets just slap something on the side with a big band-aid.

Oh and did you know about this neat little gem of "class helper" - probably the single biggest reason I can't see a use for class helpers at all.

-----------------------------
"The biggest problem with class helpers, from the p.o.v of using them in your own applications, is the fact that only ONE class helper for a given class may be in scope at any time." ... "That is, if you have two helpers in scope, only ONE will be recognized by the compiler. -----------------------------

So how does this help use solve the Observer problem? It doesn't. Maybe the code we used already bolted on some class helper which now makes all other extensibility impossible. Yeah what a wonderful way to extend classes - NOT! Interface delegation is a better design than class helpers. At least interface delegation doesn't limit you to a single feature.

Sorry but class helpers are probably the worst "feature" [if you can call it that] for the Object Pascal language that Borland could come up with.

Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Henry Vermaak
to Graeme Geldenhuys: Marco van de Voort het geskryf: You are totally over exaggerating. If FPC's only design…
Graeme Geldenhuys wrote
would be like rewriting the whole RTL and FCL! To quote the famous Florian saying: "you have no clue what you are talking about".

I feel the need to disagree here, since Marco does know what he's talking about (in my experience), not least as one of the maintainers of the RTL. Stuff like this also doesn't add to the discussion. I'm not qualified to add to this discussion, but I feel we can reach a good solution without feeling the need to hit each other upside the head.

Henry

Reply by email

Marco van de Voort
to Michael Van Canneyt: Aha, but you are very wrong there. The germs of this particular idea have been discussed…

In our previous episode, Michael Van Canneyt said:

Show quoted text 6 lines
So - let's try another approach which may prove more constructive: What are your proposals to get some kind of observer pattern implemented so it can be applied consequently throughout the classes of the FCL and LCL, without duplicating all code or subclassing all existing classes ?

First: I don't see an urgent need for such draconic measures.

Second: I don't see a good solution, exactly because the whole framework was not designed for this.

E.g. an Observer pattern typically uses interfaces, and interfaces are not designed into the framework.

Show quoted text 5 lines
I am not interested in the actual implementation of the observer pattern, just the means by which you think we can 'inject' one. Please don't bother questioning the need/desirability of this feature, consider it a given.

And that you call "constructive" ?

But anyway, I don't see any sane solution to inject it. Including proposed ones modifying base classes.

That is the whole point. If you want this, start over, and do it properly.

Reply by email

Graeme Geldenhuys
to Henry Vermaak: I feel the need to disagree here, since Marco does know what he's talking about (in my…
Henry Vermaak wrote
not qualified to add to this discussion, but I feel we can reach a good solution without feeling the need to hit each other upside the head.

Well, seeing that Marco and Florian are very quick to call people clueless and bash them in public - I thought if they can deal it out, they should be able to take some themselves. But yes this is getting nowhere - hence I suggestion to Michael to simply apply his changes and be done with it.

Marco might know the RTL, but so do others. I also know class design and design patterns very well - both are my passion in programming. So I believe I know what I am talking about as well when I say the Observer is very useful in the base classes. Maybe some of you don't know what Observer is or how it works, maybe some of you don't even know what Design Patterns are - this doesn't make them less useful.

Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Henry Vermaak
to Graeme Geldenhuys
Graeme Geldenhuys wrote 11 lines
On 19/05/2010, Henry Vermaak wrote: > >  not qualified to add to this discussion, but I feel we can reach a >  good solution without feeling the need to hit each other upside the >  head. Well, seeing that Marco and Florian are very quick to call people clueless and bash them in public - I thought if they can deal it out, they should be able to take some themselves. But yes this is getting nowhere - hence I suggestion to Michael to simply apply his changes and be done with it.

I can't find where Marco was rude, care to point it out? I think Florian's abruptness was justified, but it's better not to feed the trolls. The point I'm trying to make is that if you have a strong enough technical basis, you will convince people. Like Linus says, talk is cheap, show me the code.

Show quoted text 6 lines
Marco might know the RTL, but so do others. I also know class design and design patterns very well - both are my passion in programming. So I believe I know what I am talking about as well when I say the Observer is very useful in the base classes. Maybe some of you don't know what Observer is or how it works, maybe some of you don't even know what Design Patterns are - this doesn't make them less useful.

I don't doubt for a second that you know a lot about design patterns, but I know that Marco also does, so this is not why you are disagreeing. The point was that it opens the door for a lot of other (perhaps questionable) stuff to weasel its way into the base classes on the basis of "but you allowed the observer stuff!". Which is a justified objection, imo.

Anyway, I do hope that there is a feasible to implement this, because the observer pattern is very powerful.

Henry

Reply by email

Graeme Geldenhuys
to Marco van de Voort: In our previous episode, Michael Van Canneyt said: First: I don't see an urgent need for…
Marco van de Voort wrote
First: I don't see an urgent need for such draconic measures.

So Michael having to wait 10 years to see it implemented is called "urgent" in your eye? :)

Second: I don't see a good solution, exactly because the whole framework was not designed for this.

No need for a whole framework designed. Just adding some extra functionality. Clearly you need a code example to understand it. See the code example below.

E.g. an Observer pattern typically uses interfaces, and interfaces are not designed into the framework.

Hell no! Observer has nothing to do with interfaces! The Observer is implemented in tiOPF without interfaces. Using interfaces just makes it easier to inject Observable behaviour - but injecting behaviour is a feature of interfaces in general (not specific to Observer). The other benefit of interfaces (now that we have interface delegation) is that you only need to implement the Observer once and bolt that implementation onto other classes. Saving you lots of duplicated code and time.

Attached is a stripped down version of Observer implemented as a separate unit.

And here is how you can add Observer functionality to a class using interfaces (purely to reduce code). This is what Michael and I are proposing we do to base classes like TStrings or even TPersistent etc.

(note the final implementation my not look 100% like this - this is just a quick example):

{$interfaces corba}
  TMyClass = class(TList, IFPObserved)
  private
    FObservedHook: TObservedHook;
    property  ObservedHook: TObservedHook read FObservedHook
implements IFPObserved; // are will always access it via a interface
so it can stay private
  public
     function Add(....): Integer; override;
  end;
function TMyClass.Add(....)
begin
  inherited Add(...)
  if Assigned(ObservedHook) then
    ObservedHook.NotifyObservers(self, ooChanged);
end;

That's it! Now TMyClass can be observed. No huge amounts of code or "draconic measures" as you phrased it.

You can now add observers of that class as follows in your program:

  TMakeMeObserveSomething = class(TObject, IFPObserver)
  private
     procedure ObservedChanged(ASender: TObject;
           Operation: TObservedOperation);
  public
     procedure DoItNow;
  end;
procedure TMakeMeObserveSomething.DoItNow;
var
  intf: IFPObserved;
begin
  if MyClass.GetInterface(IFPObserved, intf) then
    intf.AttachObserver(self);
end;

In tiOPF's implementation of Observer I optimized the code that extra resources are only used when you actually use the observable functionality by adding an observer the for the first time. I also added extra optimization so that when you add many items for example to a list that it works similar to BeginUpdate; .... EndUpdate; so that observers are only notified once when a long running action is completed or after multiple items was added to a list. Similar optimization could be added the what Michael is proposing (if he hasn't implemented this yet).

Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Marco van de Voort
to Graeme Geldenhuys: Well, seeing that Marco and Florian are very quick to call people clueless and bash them…

In our previous episode, Graeme Geldenhuys said:

Show quoted text 6 lines
Marco might know the RTL, but so do others. I also know class design and design patterns very well - both are my passion in programming. So I believe I know what I am talking about as well when I say the Observer is very useful in the base classes. Maybe some of you don't know what Observer is or how it works, maybe some of you don't even know what Design Patterns are - this doesn't make them less useful.

I've an own copy of GoF btw. However knowing and even appreciating a certain pattern doesn't automatically mean it should be implemented at all costs.

Reply by email

Graeme Geldenhuys
to Henry Vermaak: I can't find where Marco was rude, care to point it out? I think Florian's abruptness…
Henry Vermaak wrote
enough technical basis, you will convince people. Like Linus says, talk is cheap, show me the code.

You are welcome to look at the tiOPF code.
http://sourceforge.net/projects/tiopf/

I also attached a simplified example to my previous reply to Macro and code to show how it would attach to a base class and how to use it.

Talk IS cheap, so see the code. :-)

disagreeing. The point was that it opens the door for a lot of other (perhaps questionable) stuff to weasel its way into the base classes

With that we should ban all modifications to FPC code because it might introduce bugs or break something. Pointless! Why not handle each "future enhancement" on a case by case basis IF they are ever suggested, and not simply ban all enhancements on a "what if" scenario. I think Michael and I have given sufficient benefits to this idea, and seeing that nobody else has proposed a better alternative (and reimplementing the RTL, FCL, LCL, fpGUI is *not* an alternative), I see no reason why this cannot be added.

Anyway, I do hope that there is a feasible to implement this, because the observer pattern is very powerful.

I'm confused. One minute it sounds like you are saying no it's a bad idea, then the next paragraph you say is this is a good idea? :)

Anyway, review the code I supplied earlier and what is available in tiOPF. Even run Demo 21 of tiOPF to see how a complete Address Book application is implemented using a database and standard components (LCL, VCL or fpGUI) and never does it need db-aware components. Every component on every form uses Observer, and thanks to the Mediator design pattern the communication is a two-way street.

Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Marco van de Voort: In our previous episode, Graeme Geldenhuys said: I've an own copy of GoF btw. However…
Marco van de Voort wrote
I've an own copy of GoF btw.

Owning a copy doesn't meant you read it or understood it. ;-)

However knowing and even appreciating a certain pattern doesn't automatically mean it should be implemented at all costs.

I believe Michael and I have listed enough examples of how it can be useful. And you couldn't show an alternative solution as Michael asked for.

Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Marco van de Voort
to Graeme Geldenhuys

In our previous episode, Graeme Geldenhuys said:

> I've an own copy of GoF btw. Owning a copy doesn't meant you read it or understood it. ;-)

Yeah. Studying means neither.

Show quoted text 5 lines
> However knowing and even appreciating a certain > pattern doesn't automatically mean it should be implemented at all costs. I believe Michael and I have listed enough examples of how it can be useful.

And I don't think useful is under discussion. The question if it warrants such deep changes.

And while Michael advocates he has thought long about it, so have I. We even discussed about TStringlist and the sad way it plugs into the VCL/LCL in the car for at leat more than an hour when we drove to Muenchen the last time.

I've been thinking about it because I really would like have Java style interface hierarchy in the container types. (Corba that is, GC/refcount not necessary), and to a lesser degree iterators. (when I was working with DECAL)

I concluded that nothing sane can be done in the current VCL/LCL, and workarounds to fix that are worse than the problem that they fix.

and you couldn't show an alternative solution as Michael asked for.

Since my point is that it doesn't make sense in the first place, it is not that strange that I can't come up with a sane way to implement it.

Reply by email

Graeme Geldenhuys
to Marco van de Voort
Marco van de Voort wrote
Yeah. Studying means neither.

Well lets see: I have written numerous technical papers/articles on the subject, been using it in commercial software for almost 10 years and presented technical and training workshops on the subject. I think I have a good knowledge on the subject.

And while Michael advocates he has thought long about it, so have I. We even discussed about TStringlist and the sad way it plugs into the VCL/LCL in the car for at leat more than an hour when we drove to Muenchen the last time.

Code evolves over time - that's a fact. Refactoring code is also a way of life (or at least should be) for developers. The only constant in code is change! Introducing Observer into the classes unit is simply code evolving - fulfilling a new software requirement that did not exist before.

Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Matt Emson: Sent from my iPhone On 19 May 2010, at 17:52, Graeme Geldenhuys I don't think so. I'd…

Matt Emson het geskryf:

Patterns are faddy - you are not going to please everyone.

Please explain and give examples where Observer will not be useful. Also, I do not know what "faddy" means.

I'd rather see a mechanism for injecting first class extensions to existing classes.

* Interfaces don't work because you need to subclass them to get the extra functionality. This is totally useless for things like TCombobox.Items or TMemo.Lines (like Michael explained) because such components uses TStrings directly.

* Class Helpers like in Delphi. Also useless because you can only extend them with one helper class at a time. So you want ComboBox.Items.IsEmpty so you create a help class do do that. Now that helper class blocks any other functionality from being added. Class Helpers were introduced in Delphi 8 - the worse release of Delphi *ever*, and with such features we can clearly see why.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Matt Emson
to Graeme Geldenhuys: Ah yes, the famous "class helper" which makes designing a class structure way more…

Sent from my iPhone

Graeme Geldenhuys wrote 8 lines
On 19/05/2010, Inoussa OUEDRAOGO wrote: > > Agreed. This mechanism exists in Delphi and is called "class helper", > see http://docwiki.embarcadero.com/RADStudio/en/Class_and_Record_Helpers Ah yes, the famous "class helper" which makes designing a class structure way more complex because their is no real structure|design - lets just slap something on the side with a big band-aid.

No, no, no!! I specifically didn't mention Class Helpers. Objective-C Categories or similar was what I had in my head.

Reply by email

Graeme Geldenhuys
to Vincent Snijders: Is there a patch to review, so I can see what this discussion is all about? I wonder if…

Vincent Snijders het geskryf:

Is there a patch to review, so I can see what this discussion is all about?

I posted some example code earlier in a reply to Marco (sorry, it's somewhere between all the noise).

I wonder if something like class helpers is able to solve this, like Matt suggested.

As I mentioned in another reply, class helpers are a pretty useless feature in Delphi and will not solve much. So the other message for reason why.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Matt Emson
to Graeme Geldenhuys: Well, seeing that Marco and Florian are very quick to call people clueless and bash them…

Sent from my iPhone

Graeme Geldenhuys wrote
maybe some of you don't even know what Design Patterns are - this doesn't make them less useful.

In my experience, often badly implemented and regularly abused. Patterns take extreme discipline. Either you FORCE programmers to use them by making it terribly difficult not to, or you don't implement them.

Reply by email

Helmut Hartl
to Graeme Geldenhuys: Well lets see: I have written numerous technical papers/articles on the subject, been…
Graeme Geldenhuys wrote 19 lines
On 20/05/2010, Marco van de Voort wrote: > Yeah. Studying means neither. > Well lets see: I have written numerous technical papers/articles on the subject, been using it in commercial software for almost 10 years and presented technical and training workshops on the subject. I think I have a good knowledge on the subject. > And while Michael advocates he has thought long about it, so have I. We even > discussed about TStringlist and the sad way it plugs into the VCL/LCL in the > car for at leat more than an hour when we drove to Muenchen the last time. > Code evolves over time - that's a fact. Refactoring code is also a way of life (or at least should be) for developers. The only constant in code is change! Introducing Observer into the classes unit is simply code evolving - fulfilling a new software requirement that did not exist before

*EXPLICIT WARNING : "ACADEMIC VIEWPOINT"*
(this means worthless in practice :-)) (or I have read many books, understood something and I am able to impress
people with wrong mathematical proofs)

Be prepared to laugh - or think about your sense of humor.

Life flows - evolution is good (at least for they who are on the winning side),
reading books opens the mind (alcohol too - but little (own) childs the most).
Patterns are super - but not if you are coding something performance critical.
Extra stuff that makes things easier is nice - I always want my VAN to be a Truck
when I am transporting something AND to be a bicycle when searching for a parking lot.

While coding OpenGL/Physics I would like to hang everybody polluting the base,
while coding our boring business stuff multitier bloatet database applications
I would like the observer. (We did databases long enough now and switched to
something more fun)

Now I contributed a whole bunch of unrelated feelings based stuff to this discussion,
trying to match the argumentative style so far. :-)

Isn't it better to to ask the right questions (at least some) before trying to swing opinions
(with brutal - but - wrong directed force) ?

1) Who decides what comes into the base ?
2) What If I am not able to respect this descision ?
3) Do I really need that red car toy on every case ? (eeh.. skip this)
4) Is there a summary of the discussion that cares about more sides of the problem ?
a) Performance Point ?
b) Memory Usage point ?
c) Embedded Usage ?
d) Crossplatform Usage ?
e) Compatibility ?
5) When is the RIGHT TIME to do that discussion ? (I certainly doubt that it is now, 2.4.2)
[To understand point 5 fully it may be good to be older than 25 years ;-)]
6) Am I speaking for my personal pleasure or am I able to consider the points mentioned under 4 ?
7) Is it good to (often) block people who want to achieve something ?
8) Is there a solution who satisfies all parties to a certain degree or are we really to dumb to find it ?
9) How to make such a change at the right time, and give more people the ability to think about it
- or give them the time to not think - not test and live with the consequences ?

The result should be a summary with pro's and con's and the ability to take a proper and thought
through decision.
(Maybe a wiki page with a summary table and the ability to vote ?
- If this would be a "democratic discussion" of course (see point 1) -

Rather than "Who has the longest ?"

(Expierience in reading, talking, teaching of course
- please forgive my english - I am not a native ;-) It should have read "... rather than who has the most "... ?)

Helmut

Reply by email

Matt Emson
to Graeme Geldenhuys: Matt Emson het geskryf: Please explain and give examples where Observer will not be…

Sent from my iPhone

Graeme Geldenhuys wrote 6 lines
Matt Emson het geskryf: > Patterns are faddy - you are not going to please everyone. Please explain and give examples where Observer will not be useful. Also, I do not know what "faddy" means.

Having used it a lot recently, I'd prefer MVC to be used with in a class library.

A Subscription mechanism is more powerful. Look at the MUSCLE C++ framework.

Iterator I use every day!!

Show quoted text 9 lines
> I'd rather see a mechanism for injecting first class extensions to > existing classes. * Interfaces don't work because you need to subclass them to get the extra functionality. This is totally useless for things like TCombobox.Items or TMemo.Lines (like Michael explained) because such components uses TStrings directly.

As Marco said - the underlying framework is fundamentally flawed. You want to patch it. You need to redesign it. You are incredibly short sighted here. Think outside of the box.

* Class Helpers like in Delphi.

No. Delphi is not the model for all change. Blinkers off. Look at Objective-C categories or the Mix-In concept.

Talk is cheap. I'm not using pascal enough to justify coding. But if I was doing this, I'd start again, as Marco suggests.

Reply by email

Graeme Geldenhuys
to Matt Emson: Sent from my iPhone On 19 May 2010, at 23:02, Graeme Geldenhuys In my experience, often…

Matt Emson het geskryf:

In my experience, often badly implemented and regularly abused.

Then whoever wrote that code you looked at has no clue what they were doing and has a near zero understanding of design patterns or OOP.

Patterns take extreme discipline.

On the contrary, design patterns are everywhere, and developers often use some form of them without even knowing. In such cases it often only requires some small form of code tuning to get a better design.

Simple example: Ever used TAction in Delphi or Lazarus? Yes? Well, then you have been using the Command pattern (well some form of the Command pattern). VCL actually has quite a few design patterns implemented. And to reiterate an earlier point I made: design patterns are *not* a code template, they are a design guideline for solving a common problem, and each design may differ in implementation.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Unknown author
Marco van de Voort wrote 23 lines
In our previous episode, Michael Van Canneyt said: > So - let's try another approach which may prove more constructive: > > What are your proposals to get some kind of observer pattern > implemented so it can be applied consequently throughout the > classes of the FCL and LCL, without duplicating all code or > subclassing all existing classes ? First: I don't see an urgent need for such draconic measures. Second: I don't see a good solution, exactly because the whole framework was not designed for this. E.g. an Observer pattern typically uses interfaces, and interfaces are not designed into the framework. > I am not interested in the actual implementation of the observer > pattern, just the means by which you think we can 'inject' one. > Please don't bother questioning the need/desirability of > this feature, consider it a given. And that you call "constructive" ?
Sorry, I'm just trying to restrict the discussion to technical matters;
Maybe I phrased that not optimally.

It's not because you don't see a need, that others don't have it; there is no point in discussing that, we will never agree on that. Just like I don't discuss religion with people.

But anyway, I don't see any sane solution to inject it. Including proposed ones modifying base classes. That is the whole point. If you want this, start over, and do it properly.

That is an impossibility, since then we cannot use it in the FCL/LCL, which is one of the requirements:

I need a solution that works with current GUI, current libraries and whatnot. What you propose is re-doing the work of 10 years, which is obviously not feasable.

I fully agree with you that it may be desirable, but practically, it is not feasable, since then we must throw away tried and trustable codebases. I am even prepared to do work on designing and implementing such an alternative scheme. But I also need a solution that works with the current codebase.

So please propose something else, something you concede is not the optimal solution, but which you are prepared to accept, lacking the optimal solution.

Michael.

Reply by email

Marco van de Voort
to Michael Van Canneyt: Observable and Observer go hand in hand. We're talking about both. Specifically, I want…

In our previous episode, Michael Van Canneyt said:

Show quoted text 5 lines
> the state of the object) and also keeps no state (the list is also in > Observable) Observable and Observer go hand in hand. We're talking about both. Specifically, I want to add observable to TPersistent.

People having object frameworks based on that class will really thank you for slowing their systems.

Reply by email

Michael Van Canneyt
to Marco van de Voort
Marco van de Voort wrote 9 lines
In our previous episode, Michael Van Canneyt said: >> the state of the object) and also keeps no state (the list is also in >> Observable) > > Observable and Observer go hand in hand. We're talking about both. > Specifically, I want to add observable to TPersistent. People having object frameworks based on that class will really thank you for slowing their systems.

Why would it slow down?

I'm not adding any calls to it. Just a call and a property which - when used in a descendent - may instantiate an auxiliary object. By default, nothing is called, and therefor there is no speed impact.

Michael.

Reply by email

Graeme Geldenhuys
to Helmut Hartl: *EXPLICIT WARNING : "ACADEMIC VIEWPOINT"* (this means worthless in practice :-)) (or I…

Helmut Hartl het geskryf:

Patterns are super - but not if you are coding something performance critical.

Then you are still struggling to understand design patterns. I'll say it again: They are a design guide for solving a common found problem. How you implement it, is up to you! Design patterns are all over the place (Compiler, RTL, FCL, VCL, LCL etc) - maybe you [or any other developer] simply didn't know that the solution implemented to solve a problem actually had a name, and the structure of the solution was documented before, with nice pretty UML diagrams.

while coding our boring business stuff multitier bloatet database applications I would like the observer. (We did databases long enough now and switched to something more fun)

Observer has nothing to do with database applications. Neither does most of the other well documented design patterns.

More examples of design patterns:

* TAction / TActionList - uses the Command pattern
* TAction in fpGUI - uses Command and Observer patterns
* Application, Screen variables used in VCL - a very crude Singleton pattern
* Compiler parsing code - probably uses the State pattern
* LCL deciding which backend library to use - a form of Abstract Factory pattern
* Lazarus IDE list of available syntax highlighters - a form of Simple Factory Method pattern

...the list goes on, and none of these are database related.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Marco van de Voort
to Michael Van Canneyt: Why would it slow down? I'm not adding any calls to it. Just a call and a property which…

In our previous episode, Michael Van Canneyt said:

Show quoted text 11 lines
>> Observable and Observer go hand in hand. We're talking about both. >> Specifically, I want to add observable to TPersistent. > > People having object frameworks based on that class will really thank you > for slowing their systems. Why would it slow down? I'm not adding any calls to it. Just a call and a property which - when used in a descendent - may instantiate an auxiliary object. By default, nothing is called, and therefor there is no speed impact.

How do you detect in an observable that the state changed ? Usually this is done by setting a flag at any write operation to the object.

Reply by email

Marco van de Voort
to Graeme Geldenhuys: Helmut Hartl het geskryf: Then you are still struggling to understand design patterns.…

In our previous episode, Graeme Geldenhuys said:

Show quoted text 7 lines
Helmut Hartl het geskryf: > Patterns are super - but not if you are coding something performance > critical. Then you are still struggling to understand design patterns. I'll say it again: They are a design guide for solving a common found problem. How you implement it, is up to you!

It's never the religion. The followers must not be true. Maybe we should burn them at the stake and sacrifice a chicken to be sure? Hahahaha.

I like what is in the introduction of the GoF book most. Only guidelines..., no definitive truths main tasks is to fixate jargon about patterns ..., everybody has to figure out for themselves if they apply to their situation.

The authors themselves

Design patterns are all over the place

Yes. But nobody has said you have to stuff each and everyone of them in each piece of software and have support for all of them in your library.

So this is not a vote of confidence in patterns, but an fundamental extension and direction change of the runtime library, and IMHO it should be treated like that, not snuck in via a back-alley.

Apparantly we are going try to hybridize the current runtime library with new development in a new direction.

Reply by email

Michael Van Canneyt
to Marco van de Voort: In our previous episode, Michael Van Canneyt said: How do you detect in an observable…
Marco van de Voort wrote 15 lines
In our previous episode, Michael Van Canneyt said: >>> Observable and Observer go hand in hand. We're talking about both. >>> Specifically, I want to add observable to TPersistent. >> >> People having object frameworks based on that class will really thank you >> for slowing their systems. > > Why would it slow down? > > I'm not adding any calls to it. Just a call and a property which - when used in a > descendent - may instantiate an auxiliary object. By default, nothing is > called, and therefor there is no speed impact. How do you detect in an observable that the state changed ? Usually this is done by setting a flag at any write operation to the object.

Of course, but this is up to the developer. I offer the mechanism, the developer to use it.

Michael.

Reply by email

Graeme Geldenhuys
to Matt Emson: Sent from my iPhone On 20 May 2010, at 07:52, Graeme Geldenhuys Having used it a lot…

Matt Emson het geskryf:

Having used it a lot recently, I'd prefer MVC to be used with in a class library.

MVC often uses Observer! Model-GUI-Mediator (MGM) that I implemented in tiOPF and use daily in our current software is very similar to MVC without the need of creating descendant "view" components. MGM is a combined effort of Observer and Mediator.

A Subscription mechanism is more powerful. Look at the MUSCLE C++ framework.

I don't know the Subscription mechanism using in Muscle C++, but from the name alone, it sounds exactly like what Observer does. Other components/objects subscribe to some other class, so that it can be notified of any changes. We would like this subscription idea in the base classes because they will be incredibly useful to many - and the Observer implementation will do just that.

Iterator I use every day!!

Same here, and Iterator is the heart of tiOPF. I abandoned the proposal to include Iterator in some of the base classes (like what Java has) simply because I could see many argue the same thing as we are arguing now. At least for the Iterator I found an external solution to the problem, so I can now iterate any of the base classes with easy.

Unfortunately for the subscription/observer/observable functionality, there is no external solution - hence our proposal that the base classes get the functionality directly. If there was an alternative solution, Michael and I would already have been using it - instead of arguing the point here.

As Marco said - the underlying framework is fundamentally flawed. You want to patch it. You need to redesign it. You are incredibly short sighted here. Think outside of the box.

Yeah well, redesigning the RTL, FCL, LCL is not an option either. It will take the next 10 years to implement; you will loose all compatibility with Delphi and existing code....all because you only wanted to add one rather simple feature. Letting the current code evolve (like all software does) is a much better and simpler solution.

Talk is cheap. I'm not using pascal enough to justify coding. But if I was doing this, I'd start again, as Marco suggests.

Yes, and I have bills to pay and no time to waist with such stupid ideas. I code in Object Pascal for a living. Just because there is a problem (or missing feature) in the underlying framework code, doesn't mean it must be rewritten from scratch! Evolving code and Refactoring are common methods of improving EXISTING code.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Joost van der Sluis
to Graeme Geldenhuys: Michael, I have two options to solve this: 1) Ignore Marco and implement it any way. I…
Graeme Geldenhuys wrote 7 lines
On 19 May 2010 16:20, Michael Van Canneyt wrote: > I have an implementation in place, which doesn't affect too much the > existing classes: it adds 1 public property and one private method; There is > no impact on code efficiency. 1) Ignore Marco and implement it any way. I think you have just as much say as Macro on what goes into the FPC.

Ok, Graeme, I haven't read the rest of the waterfall of messages in this thread yet. But here you are going too far. Way too far. Imho we don't need someone in our community who tries to drive the community apart by setting people up against each other.

It's also not necessary to send looooonnggg mails to discuss something as this. It only costs us energy, which we can spend better. If the result of this sort of discussions is that we loose developers, we can only loose.

You are the only one gaining energy with discussions like this, it seems. Stop that. It's doesn't help anyone.

We have to discuss things here reasonable. It's shoudn't be the case that you win when you are the loudest screamer.

Joost.

Reply by email

Henry Vermaak
to Graeme Geldenhuys: You are welcome to look at the tiOPF code. http://sourceforge.net/projects/tiopf/ I also…
Graeme Geldenhuys wrote 6 lines
On 20/05/2010, Henry Vermaak wrote: >  Anyway, I do hope that there is a feasible to implement this, because >  the observer pattern is very powerful. I'm confused. One minute it sounds like you are saying no it's a bad idea, then the next paragraph you say is this is a good idea?  :)

No, I said it's powerful. I'm all for getting the extra functionality, like I'm sure everyone is. I just don't have an opinion on how this should be added.

Henry

Reply by email

Graeme Geldenhuys
to Joost van der Sluis: Ok, Graeme, I haven't read the rest of the waterfall of messages in this thread yet. But…

Joost van der Sluis het geskryf:

Show quoted text 5 lines
> 1) Ignore Marco and implement it any way. I think you have just as > much say as Macro on what goes into the FPC. thread yet. But here you are going too far. Way too far. Imho we don't

Well my statement was true wasn't it? Michael's opinion should count too. Why must Marco always get his way? Why must Marco always disagree with all new proposals.

Short enough?

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Joost van der Sluis
to Graeme Geldenhuys: And my prototype implementation of TActions support in fpGUI using Observer is another…
Graeme Geldenhuys wrote 10 lines
On 19 May 2010 19:24, Michael Van Canneyt wrote: > > that I actually need and why I implemented observer in the first place: to > be able to observe for instance the changes in TMemo.Lines or > TCombobox.Items. (and these are from real-world examples). And my prototype implementation of TActions support in fpGUI using Observer is another example. I totally eliminated the TBasicActionLink class hierarchy yet have the same functionality as LCL/VCL Actions with less (and clearer) code.

This is what Marco is afraid about: that people want to alter the base-design, because 'their design is better'. That's certainly not what we should do. But adding the observer-possibility to the base classes is ok with me. It doesn't change the design, it adds something to it. something that I would implement the same way if I would re-design it.

Show quoted text 5 lines
> No-one objected then, I see no reason why this minor change is > so questionable. I think Marco makes it his mission in life to disagree with everything I say. :-(

Trolling again? (It's not less a troll if there's a smiley behind it. Again an useless remark, only to grieve some others)

Joost.

Reply by email

Helmut Hartl
to Graeme Geldenhuys: Joost van der Sluis het geskryf: Well my statement was true wasn't it? Michael's opinion…
Graeme Geldenhuys wrote 13 lines
Joost van der Sluis het geskryf: >> 1) Ignore Marco and implement it any way. I think you have just as >> much say as Macro on what goes into the FPC. >> > thread yet. But here you are going too far. Way too far. Imho we don't > Well my statement was true wasn't it? Michael's opinion should count too. Why must Marco always get his way? Why must Marco always disagree with all new proposals. Short enough?

I personally met, talked to, and respect Michael and Marco (SYSTEMS/Munich). I agree to Joosts statement.

Can someone please explain to me what the change to TObject will do to my STM implementation ?
(Relying on memory layout, lockfree algo's and size ... )

Beware you need to make your self familiar with :
http://www.cl.cam.ac.uk/research/srg/netos/lock-free/ at least: http://en.wikipedia.org/wiki/Software_transactional_memory If you want to give statements with a clue - (and after that you still cannot answer my question).

A redisign of classes is ok as it implies the chance to adobt code to it. But fundamential changes in an stability release ?

helmut

Reply by email

Jonas Maebe
to Helmut Hartl
Helmut Hartl wrote
But fundamential changes in an stability release ?

All changes are always committed first to trunk. It is indeed unlikely that a change like the one under discussion currently, if performed, would still be added to 2.4.2 (as also indicated in the initial message of this thread).

Jonas

Reply by email

Michael Van Canneyt
to Helmut Hartl: I personally met, talked to, and respect Michael and Marco (SYSTEMS/Munich). I agree to…
Helmut Hartl wrote 20 lines
Am 20.05.10 10:29, schrieb Graeme Geldenhuys: > Joost van der Sluis het geskryf: > >>> 1) Ignore Marco and implement it any way. I think you have just as >>> much say as Macro on what goes into the FPC. >>> >> thread yet. But here you are going too far. Way too far. Imho we don't >> > Well my statement was true wasn't it? Michael's opinion should count too. > Why must Marco always get his way? Why must Marco always disagree with all > new proposals. > > Short enough? > I personally met, talked to, and respect Michael and Marco (SYSTEMS/Munich). I agree to Joosts statement. Can someone please explain to me what the change to TObject will do to my STM implementation ? (Relying on memory layout, lockfree algo's and size ... )

There is no change to TObject.

One additional (interface) property and 2 methods are added to TPersistent (one is the private getter of the property).

They are not used directly in TPersistent or in TComponent. Retrieving the interface (only done by other components/objects that wish to observe) will instantiate an auxiliary object.

The names will be such that the likelihood that they actually conflict with existing code is very small indeed; Of course we cannot guarantee this 100%, since we don't know all existing code out there.

I think the last change to TObject was the addition of 'UnitName', for Delphi 2009 compatibility. It actually broke some of my code, but I just renamed my property using search&replace, recompiled, and that was it.

Michael.

Reply by email

Florian Klaempfl
to Unknown author: Sorry, I'm just trying to restrict the discussion to technical matters; Maybe I phrased…
I need a solution that works with current GUI, current libraries and whatnot. What you propose is re-doing the work of 10 years, which is obviously not feasable.

Can you give a real world example what you want to do with it?

I've no opinion if it's usefull to add or not, I use TPersistent+ too little but my concern is: if I create an observer for an instance, I'd expect to get notified about every change to the instance. But I cannot see how this will be achieved, no existing class is prepared for this? Shouldn't be ReferenceInterface simply extended with new operations?

Reply by email

Michael Van Canneyt
to Jonas Maebe: All changes are always committed first to trunk. It is indeed unlikely that a change like…
Jonas Maebe wrote 8 lines
On 20 May 2010, at 10:46, Helmut Hartl wrote: > But fundamential changes in an stability release ? All changes are always committed first to trunk. It is indeed unlikely that a change like the one under discussion currently, if performed, would still be added to 2.4.2 (as also indicated in the initial message of this thread).

100% correct.

Michael.

Reply by email

Matt Emson
to Graeme Geldenhuys: Matt Emson het geskryf: Then whoever wrote that code you looked at has no clue what they…
Graeme Geldenhuys wrote 8 lines
Matt Emson het geskryf: > In my experience, often badly implemented and regularly abused. > Then whoever wrote that code you looked at has no clue what they were doing and has a near zero understanding of design patterns or OOP.

No. The problem with Patterns is that you need to embrace or reject. There's no middle ground.

> Patterns take extreme discipline. > On the contrary, design patterns are everywhere,

Ah, yes. The old retro-fit argument. Name it and it shall be "so". You guys crack me up ;-)

Patterns take extreme discipline because unless you adhere to them, your code gets incredibly convoluted. Been there, seen it. Seen people use them religiously, find a situation where performance tanked and use unholy hacks to get around the issues. Again - they are fine, so long as the development team wholeheartedly embraces them. Otherwise they are an incredibly fine way to shoot yourself in the foot.

Reply by email

Inoussa OUEDRAOGO
to Graeme Geldenhuys: Ah yes, the famous "class helper" which makes designing a class structure way more…

2010/5/19 Graeme Geldenhuys :

Show quoted text 19 lines
On 19/05/2010, Inoussa OUEDRAOGO  wrote: > > Agreed. This mechanism exists in Delphi and is called "class helper", >  see http://docwiki.embarcadero.com/RADStudio/en/Class_and_Record_Helpers Ah yes, the famous "class helper" which makes designing a class structure way more complex because their is no real structure|design - lets just slap something on the side with a big band-aid. Oh and did you know about this neat little gem of "class helper" - probably the single biggest reason I can't see a use for class helpers at all. ----------------------------- "The biggest problem with class helpers, from the p.o.v of using them in your own applications, is the fact that only ONE class helper for a given class may be in scope at any time." ... "That is, if you have two helpers in scope, only ONE will be recognized by the compiler. -----------------------------

This is the Delphi implementation limitation : _why_ should FPC implement such limitation ?
Even in the case of (questionable)Delphi compatibility this limitation may be activated in Delphi mode.

Show quoted text 6 lines
So how does this help use solve the Observer problem? It doesn't. Maybe the code we used already bolted on some class helper which now makes all other extensibility impossible. Yeah what a wonderful way to extend classes - NOT! Interface delegation is a better design than class helpers. At least interface delegation doesn't limit you to a single feature.

Again, _why_ should FPC implement such limitation ?

Sorry but class helpers are probably the worst "feature" [if you can call it that] for the Object Pascal language that Borland could come up with.

That is your opinion. Mine is that properly implemented, Class Helper as a _class extension mechanism_ is
a very powerfull tool; Change the name if you want, consider the concept, not the name please.

Inoussa O.

Reply by email

Michael Van Canneyt
to Florian Klaempfl: Can you give a real world example what you want to do with it? I've no opinion if it's…
Florian Klaempfl wrote 7 lines
schrieb: > > I need a solution that works with current GUI, current libraries and > whatnot. What you propose is re-doing the work of 10 years, which is > obviously not feasable. Can you give a real world example what you want to do with it?

Like I said, observe TMemo.Strings for changes. Or TObjectList: additions/removal of objects, so I can update a listview that represents the objects in the list.

Note that these classes already have extremely simple notification mechanisms; It is an enhancement of the existing mechanism. the TFPList class for instance will not get the notification, as it's purpose is raw speed, and a clear should not trigger OnChange for every removed object.

I've no opinion if it's usefull to add or not, I use TPersistent+ too little but my concern is: if I create an observer for an instance, I'd expect to get notified about every change to the instance. But I cannot see how this will be achieved, no existing class is prepared for this?

Not every change. What you get notified about is defined by the class that uses the observable interface. TStrings will notify you of additions/removals, and TList/TObjectList as well. TFPList will not. This should (and will) be documented.

One can discuss for instance whether setting TComponent.Name should trigger the change. To my taste, it should not, since normally one doesn't change the name during the lifetime of a TComponent.

Shouldn't be ReferenceInterface simply extended with new operations?

I don't think so, for 3 reasons:

1. It works on TComponent only. The solution is needed at TPersistent level. (TStrings/TCollection descend from TPersistent).
2. It is a COM interface, which introduces a lot of overhead. (init/finalization and the whole reference counting mess) My implementation uses CORBA interfaces to avoid that.
3. It would definitely break Delphi compatibility, as ReferenceInterface is a Delphi-defined interface :/ (Maybe it is even a .NET one, but I don't know that)

Michael.

Reply by email

Graeme Geldenhuys
to Joost van der Sluis: This is what Marco is afraid about: that people want to alter the base-design, because…

Joost van der Sluis het geskryf:

This is what Marco is afraid about: that people want to alter the base-design, because 'their design is better'. That's certainly not what we should do.

Well luckily that is of no concern to FPC developers. Such changes would be discussed in the Lazarus or fpGUI projects. The discussion here (and only concern to FPC developers) is adding the ability to observe base classes. Nothing more.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Marco van de Voort
to Matt Emson: No. The problem with Patterns is that you need to embrace or reject. There's no middle…

In our previous episode, Matt Emson said:

Patterns take extreme discipline because unless you adhere to them, your code gets incredibly convoluted. Been there, seen it.

When applying any algorithm or technique, you need to see if it fits, and if it is no overkill, patterns are no different there.

When I first came into contact with patterns I really liked the idea. The authors just noted they wanted to write down the commonly used patterns, to create a common jargon, and a discussion of basic pro and con's.

I'm not anti-pattern, and it is not patterns that are under discussion here. Neither is that there are a lot of clueless pattern followers that try to stuff 6 patterns into what is basically a for i:integer= loop and creating an object for each bit of the integer, because they are so cool and modern.

The point is the question if a given, existing framework should be patched on such a deep and crucial level with support for a new concept, just because somebody wants to use the pattern in some package, and he needs a hook in the framework.

This really sets a dangerous precedent IMHO, and it is only a matter of time the next proposal pops up.

Moreover it sets a precendent that suggestions like this that are suggested by users are rejected, but if two FPC devels have an itch, it is forced in.

It is one of the perils of open source I guess. Because the source is clearly open, every itch must be fixed in the main source and framework.

That's also why I don't understand why Graeme is so angry. I give proposals from FPC devels the same scrutiny and criticism, on the same basis (delphi compat and not part of commonly shared direction) as his proposals. In my book that is what fairness is about.

Reply by email

Graeme Geldenhuys
to Matt Emson: No. The problem with Patterns is that you need to embrace or reject. There's no middle…

Matt Emson het geskryf:

No. The problem with Patterns is that you need to embrace or reject. There's no middle ground.

DESIGN PATTERNS ARE NOT CODE TEMPLATES. YOU decide how to implement them, and if you did a s**t job it's your fault.

Patterns take extreme discipline because unless you adhere to them, your code gets incredibly convoluted. Been there, seen it. Seen people use

OK we just confirmed that you have no clue about OOP or design patterns, so I'll stop replying to your posts. You are wasting my time and not contributing to the ,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Florian Klaempfl
to Michael Van Canneyt: Like I said, observe TMemo.Strings for changes. Or TObjectList: additions/removal of…
Show quoted text 13 lines
On Thu, 20 May 2010, Florian Klaempfl wrote: > schrieb: >> >> I need a solution that works with current GUI, current libraries and >> whatnot. What you propose is re-doing the work of 10 years, which is >> obviously not feasable. > > Can you give a real world example what you want to do with it? Like I said, observe TMemo.Strings for changes.

Doesn't the OnChange event solve this for gui classes already?

Not every change. What you get notified about is defined by the class that uses the observable interface.

Is this still an observer then?

and TList/TObjectList as well.

They are no TPersistent descendents.

Reply by email

Matt Emson
to Graeme Geldenhuys: Matt Emson het geskryf: MVC often uses Observer! Model-GUI-Mediator (MGM) that I…
Graeme Geldenhuys wrote 7 lines
Matt Emson het geskryf: > Having used it a lot recently, I'd prefer MVC to be used with in a > class library. > MVC often uses Observer!

And? I've never said the observer pattern was bad. I've only ever said that retrofitting it is bad. If I advocated a new framework - MVC would be the direction I would like to see it go.

Model-GUI-Mediator (MGM)

I'd prefer complete segregation of controller and view to be honest. Cleaner.

Show quoted text 6 lines
> A Subscription mechanism is more powerful. Look at the MUSCLE C++ > framework. > I don't know the Subscription mechanism using in Muscle C++, but from the name alone, it sounds exactly like what Observer does.

It is like an uber-Observer. It allows Observable instances to specify what data they publish about themselves (think "nodes on a tree") and for the Subscribers to choose any/all of the items to observe. The Subscription mechanism can be internal, but equally cross process. The MUSCLE implementation of it works a lot like the Message passing in Haiku, but across various domains (e.g. TCP/IP comms between machines) with the notion of being able to specify a tree of published data items and a mechanism to subscribe to changes of those items.

Show quoted text 7 lines
> As Marco said - the underlying framework is fundamentally flawed. You > want to patch it. You need to redesign it. You are incredibly short > sighted here. Think outside of the box. > Yeah well, redesigning the RTL, FCL, LCL is not an option either. It will take the next 10 years to implement;

Why? A complete rewrite might take some time, but equally you could fork the RTL, FCL, LCL and then refactor them over time, just as you seem to want to anyway. I don't see why this isn't your response anyway. Isn't that the "open source" way? Contribute/Refactor/Reject/Argue/Fork? :P

you will loose all compatibility with Delphi and existing code....

Ah, so Delphi compatibility is important now? If you want to refactor the RTL as you state, you will still need to lose a certain amount of compatibility anyway. I don't see why this is an issue. Create a Facade if it is that important :)

all because you only wanted to add one rather simple feature.

Simple for who? Nothing about the Observer pattern is simple unless you understand what it is and why it exists.

Show quoted text 5 lines
> Talk is cheap. I'm not using pascal enough to justify coding. But if I > was doing this, I'd start again, as Marco suggests. > Yes, and I have bills to pay and no time to waist with such stupid ideas.

I expect Marco feels the same way :)

I code in Object Pascal for a living.

Oh dear :-) I got off that horrible train wreck a few years back.

Just because there is a problem

Everything is a problem to someone. It's just one of those unfortunate realities one must deal with :)

Reply by email

Joost van der Sluis
to Helmut Hartl: *EXPLICIT WARNING : "ACADEMIC VIEWPOINT"* (this means worthless in practice :-)) (or I…
Helmut Hartl wrote
*EXPLICIT WARNING : "ACADEMIC VIEWPOINT"* (this means worthless in practice :-)) (or I have read many books, understood something and I am able to impress people with wrong mathematical proofs)

;) Nice.

To avoid the idea that something 'magical' is going on in the decision process, maybe it's useful to clarify it somewhat. This is no official statement, just an explanation how it in practice mostly works.

1) Who decides what comes into the base ?

First principle is that the one who implements something decides how it is done.

If there are conflicting interests, the core team decides.

In this case (general rtl/fcl) that means that Michael, Marco (and I?) decide. (The order of names is not randomly chosen) But in principle we'll try to find an agreement. (As you can see now if you follow the thread about it)

If the problem remains, other core people can also try to help to find a solution. Finally Florian decides. He doesn't like to do that, but all other members are likely to silently accept his decisions if he does.

Again, this is nothing official, but I think that this is how it works.

2) What If I am not able to respect this descision ?

You can write long mails to the mailinglist. If you see that no-one of the core-teams answers them, I would say that you can better stop. As your mails won't change anything.

3) Do I really need that red car toy on every case ? (eeh.. skip this)

I will. (skip)

Show quoted text 7 lines
4) Is there a summary of the discussion that cares about more sides of the problem ? a) Performance Point ? b) Memory Usage point ? c) Embedded Usage ? d) Crossplatform Usage ? e) Compatibility ?

I think that the core-team are able to see all affects in these points. And they will discuss some. And if that leads to a decision that is technical inevitable, that eases the problem. (ie: a quick decision will be made)

5) When is the RIGHT TIME to do that discussion ? (I certainly doubt that it is now, 2.4.2)

It's discussed earlier in smaller groups. Now there was a slight remark of someone that started the discussion. That's no problem. We aren't discussing something that's related to 2.4.2. It could last a year (or even years) before this is release-ready. Best time to discuss this finally may be when we see each other in the real world. ;) (That's pretty soon)

Show quoted text 17 lines
[To understand point 5 fully it may be good to be older than 25 years ;-)] 6) Am I speaking for my personal pleasure or am I able to consider the points mentioned under 4 ? 7) Is it good to (often) block people who want to achieve something ? 8) Is there a solution who satisfies all parties to a certain degree or are we really to dumb to find it ? 9) How to make such a change at the right time, and give more people the ability to think about it - or give them the time to not think - not test and live with the consequences ? The result should be a summary with pro's and con's and the ability to take a proper and thought through decision. (Maybe a wiki page with a summary table and the ability to vote ? - If this would be a "democratic discussion" of course (see point 1) -

All good remarks. I think they are taken into consideration. But we don't want that it costs too much time. Setting up a wiki, a vote system etc. doesn't help us here.

Joost.

Reply by email

Michael Van Canneyt
to Florian Klaempfl: Doesn't the OnChange event solve this for gui classes already? Is this still an observer…
Florian Klaempfl wrote 16 lines
Michael Van Canneyt schrieb: > > > On Thu, 20 May 2010, Florian Klaempfl wrote: > >> schrieb: >>> >>> I need a solution that works with current GUI, current libraries and >>> whatnot. What you propose is re-doing the work of 10 years, which is >>> obviously not feasable. >> >> Can you give a real world example what you want to do with it? > > Like I said, observe TMemo.Strings for changes. Doesn't the OnChange event solve this for gui classes already?

Yes, but it is too primitive. We need a unified interface, universally applicable.

> Not every change. What you get notified about is defined by the class > that uses the observable interface. Is this still an observer then?

Of course. It observes changes. When you look at a thermometer, you don't expect to be notified that it's color changes (through age), but just that the temperature changes :-)

> and TList/TObjectList as well. They are no TPersistent descendents.

I know, but they will expose the same interface as TPersistent.

Michael.

Reply by email

Graeme Geldenhuys
to Florian Klaempfl: Can you give a real world example what you want to do with it? I've no opinion if it's…

Florian Klaempfl het geskryf:

Can you give a real world example what you want to do with it?

* This applies to fpGUI's implementation. TfpgAction can be observer by other components like TfpgButton, TfpgMenuItem etc.. The Action instance is changed, and the observers are notified about this change automatically. No need for a parallel hierarchy like TBasicActionLink and the family of descendants.

* A text editor which uses TStrings as a buffer (property Lines). Scrollbars and Gutter can observe the Editor.Lines property and adjust accordingly as the content of Editor.Lines change. Similar applies to TMemo.Lines etc...

* A StringGrid component observes a Dataset. As records/fields change in the dataset, so the grid is automatically updated. No need for DB-aware components. This can be applied to any components (TLabel, TEdit, TComboBox etc.)

* You have a business object that is based off TPersistent. This business object represents a business report. You have two windows each with a TChart component displaying visually the results of that report (say a line chart and a pie chart). The two TChart components are observers of the business object. As the business object's data changes the two reports are automatically updated (a nice "what if" scenario like often done in spreadsheet programs).

* A spellchecker component observers the TMemo.Lines property. As the Lines property changes the spellchecker get notified and knows exactly what line was modified and can spellcheck that specific line only. The notification system also gives the reason for the change: was it a simple line change, line addition, line removal etc.. The Spellchecker can then act accordingly.

These are just a few things I would like to implement in our applications. I am sure, given sufficient time, I can think of a lot more real-world uses.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Matt Emson
to Graeme Geldenhuys: Matt Emson het geskryf: DESIGN PATTERNS ARE NOT CODE TEMPLATES. YOU decide how to…
Graeme Geldenhuys wrote
OK we just confirmed that you have no clue about OOP or design patterns,

HAHAHAHAHAHAHAHAHAHA!! Wow. Your ego is too much for me.

so I'll stop replying to your posts.

Good. Please stop replying to the entire thread at the same time. None of us understand design patterns, honest. We're all wasting your valuable time.

You are wasting my time and not contributing to the ... "can't get my own way - throw toys out of pram.", I think I

have your measure.

Whether of not I understand design patterns is not the issue here - the issue is your inability to discuss anything without confrontation.

Do I understand OOP? Yes. Very well. I've used it on a daily basis for more years than I care to remember (15?)
Are Design Patterns an essential part of OOP? No. Absolutely *not*. Like anything, they are a tool, a helper, a pointer. Nothing more. Have I created Object Persistence mechanisms from scratch? Yes. Have I created MVC frameworks from scratch? Yes.
Have I seen the carnage created when other people use Patterns for the sake of Patterns without understanding all the ramifications? Hell yeah. Have I had to pick up the pieces? Yes, too many times. Did I need to force the developers of my given environment to implement hooks in to some patterns or another to do this? No. Did I find it necessary to insult people in the process of my career? Probably, but that is just me :)

Reply by email

Paul van Helden
to Graeme Geldenhuys: Matt Emson het geskryf: DESIGN PATTERNS ARE NOT CODE TEMPLATES. YOU decide how to…
Matt Emson wrote 13 lines
Graeme Geldenhuys wrote: > OK we just confirmed that you have no clue about OOP or design patterns, HAHAHAHAHAHAHAHAHAHA!! Wow. Your ego is too much for me. > so I'll stop replying to your posts. Good. Please stop replying to the entire thread at the same time. None of us understand design patterns, honest. We're all wasting your valuable time. > You are wasting my time and not contributing to the discussion at hand. Right... "can't get my own way - throw toys out of pram.", I think I have your measure.

Dear All,

Sometimes when this list has a busy day, I consider unsubscribing or at least having my email client file the messages into a folder automatically (which means I never get around to reading it).

Can we all please agree to have "chatty" style messages done in an IRC channel, or wiki discussion page, or whatever? For example, while I enjoyed the joke link as much as anyone else, imagine how full our inboxes would be today if everyone who read it thought themselves important enough to reply to the whole list "Those are brilliant. I love the Java one". (Sorry Graeme).

I follow this list because I learn so much from it. I don't want to unsubscribe from it, so may I kindly suggest a little restraint so that the messages remain either questions or helpful answers? Even a debate like this is OK if the arguments are well presented and the volume of messages remain low. Having a heated debate with dozens of messages in one morning on an email list is not optimal, IMO. At least in a forum one could unsubscribe from a particular thread. Please realize that your message is reaching thousands of inboxes and might only really be interesting (apart from entertainment value) to a few. This thread (as are most others) is interesting, but many of the messages are not. Sure, if you want to share a relevant and funny joke like Vinzent did and you believe it will lighten up everybody's day, send it, but can we at least agree on some restraint? It is certainly entertaining to see Greame blowing his top, but so are soap operas, and I don't really have the time for it. (Sorry again Graeme - please don't ever leave fpc-devel, your efforts are hugely appreciated and you are much respected I'm sure).

Or do I have it completely wrong and the fpc-devel list is small so anything goes?

Another message that doesn't add valuable content! (This one). Are there rules or guidelines for what gets discussed here and how?

My suggestion would be to go through a checklist like this before you hit the Reply button:

1. Is it
a. a relevant question; or
b. a helpful answer (will someone learn from it?); or c. a well thought-out technical argument to an important debate (with examples, references, etc)?
d. none of the above (No)
2. Did I spend more than a few minutes crafting it?
3. Have I re-read it at least 3 times before imposing it onto thousands of inboxes and committing it to permanent record?
If your answer is No to any of the above, consider working on your message a bit more or not sending it. These messages generate content that will outlive us all. Tip (imo): if a message doesn't start with a salutation, perhaps then the checklist needs to be consulted. (And listing your credentials and extensive experience might only be of interest to a recruiter).

Or perhaps a little chit-chat is OK too. We are a community of social animals after all. But perhaps we can restrain ourselves on days with lots of posts so as to not lose readers? Or perhaps we don't care about losing lurkers like myself.

You decide, but my delete-button-finger is aching!

Kind regards,

Paul.

B.t.w. this message fails my proposed checklist! ;-)

Reply by email

Jonas Maebe
to Paul van Helden
Paul van Helden wrote
Another message that doesn't add valuable content! (This one). Are there rules or guidelines for what gets discussed here and how?

Not really, other than about the "what": things related to the development of FPC.

You're right that this thread got out of hand in several places. I tried to control it somewhat with off-list mails to some of the people involved, but I probably should have sent more such mails and/or maybe made it moderated.

I am overall more lenient on this list than on fpc-pascal because this is list has fewer subscribers, but it turns out to be more than I thought (fpc-pascal has 1019 subscribers, this one has 585).

I'll try to keep things on this list more in check in the future. And I've moderated the thread now.

Jonas
FPC mailing lists admin

Reply by email

Vincent Snijders
to Graeme Geldenhuys: Vincent Snijders het geskryf: I posted some example code earlier in a reply to Marco…
Graeme Geldenhuys wrote 7 lines
Vincent Snijders het geskryf: > Is there a patch to review, so I can see what this discussion is all > about? I posted some example code earlier in a reply to Marco (sorry, it's somewhere between all the noise).

I am sorry, but I cannot find the code changes in the classes unit you propose. Can you give me a link in the archives or a date/time that you sent that mail? To be sure I don't mean the uses of the patches classes unit, but the actual changes in the classes unit.

Show quoted text 6 lines
> I wonder if something like class helpers is able to solve this, > like Matt suggested. As I mentioned in another reply, class helpers are a pretty useless feature in Delphi and will not solve much. So the other message for reason why.

Then they must be designed/implemented better to support multiple extensions for a particular class. Sorry I used the wrong word, Matt.

Vincent

Reply by email

Marco van de Voort
to Vincent Snijders

In our previous episode, Vincent Snijders said:

Show quoted text 8 lines
>> I wonder if something like class helpers is able to solve this, >> like Matt suggested. > > As I mentioned in another reply, class helpers are a pretty useless feature > in Delphi and will not solve much. So the other message for reason why. Then they must be designed/implemented better to support multiple extensions for a particular class. Sorry I used the wrong word, Matt.

I think the Delphi devels had the same choice as Jonas' answer to the Object Pascal categories. Doing it better probably requires changing the object model, change of object hierarchy, and likewise incompatible changes.

Reply by email

Vincent Snijders
to Vincent Snijders: I am sorry, but I cannot find the code changes in the classes unit you propose. Can you…
Vincent Snijders wrote 14 lines
Graeme Geldenhuys schreef: > Vincent Snijders het geskryf: >> Is there a patch to review, so I can see what this discussion is all >> about? > > I posted some example code earlier in a reply to Marco (sorry, it's > somewhere between all the noise). > I am sorry, but I cannot find the code changes in the classes unit you propose. Can you give me a link in the archives or a date/time that you sent that mail? To be sure I don't mean the uses of the patches classes unit, but the actual changes in the classes unit.

I found it, it got misclassified in my email client. In the archives unreadable unfortunately: http://lists.freepascal.org/lists/fpc-devel/2010-May/020032.html

Vincent

Reply by email

Dimitri Smits
Graeme Geldenhuys wrote
> Patterns are faddy - you are not going to please everyone. Please explain and give examples where Observer will not be useful. Also, I do not know what "faddy" means.

one of the first rules when using GoF book/patterns is: use them wisely/appropriately.

that said, I've encountered many design pattern noobs who made it a fetish to use as much patterns as possible, whereever possible, when first introduced to the notion. At times, this discussion seems like one of those.

don't get me wrong, the observer/observable (or publish/subscriber) is a nice pattern and at times useful at other times sorely needed, but yet at other times unneeded.

If I understand correctly, you want to implement something like a multicast eventsystem? (ISO single event handlers)

Why it has to be on TPersistent is beyond me.
Can an implementation not be made using a "global" registry where you can link your instance with the other instances? Every time the subscribers need to be made aware of the occurrance of some "event", you can "multicast" using "self" and maybe the event-identifier?

Either way, you still need to trigger a notification to your subscribers that your objects' state has changed and a way to tell it WHAT it triggered.

And either way, you definately need a clean separation of concerns.

Show quoted text 7 lines
> I'd rather see a mechanism for injecting first class extensions to > existing classes. * Interfaces don't work because you need to subclass them to get the extra functionality. This is totally useless for things like TCombobox.Items or TMemo.Lines (like Michael explained) because such components uses TStrings directly.

the way others tried to make it clear is the notion of "java interfaces". By which they mean the AWT eventlisteners, I presume?

it goes (from memory of times gone by) a bit like so:

we have an interface that has 2 methods.

interface WindowMessageHandler {
  public Open(...);
  public Close(...);
}

you have your Window class that has 2 public methods & 1 arbitrarely scoped method per fireEvent: Window {
...

  public void attachWindowMessageHandler(WindowMessageHandler wmh);
  public void removeWindowMessageHandler(WindowMessageHandler wmh);
  protected void fireOpen() {
     // loop over the internal list and call Close(...)
  }
  protected void fireClose() {
     // loop over the internal list and call Close(...)
  }

}

When your event occurs, you still need to call fireOpen() or fireClose() to notify all your listeners, and just as with events, you need to parametrise them, so custom developed every time you have something new and not nicely generalised/abstracted.

Something similar is easily done with pascal interfaces. Even outside of every class! With interfaces is maybe not so easily done if you don't understand them or their use, but it gives you at least independence on implementation level and does not restrict you to use a specific type.

Either way, you still need to (somehow) link back. Does your observer know it gets attached to that specific instance of observable? (ie: did it link to it by itself or by its creator?) How does the observed object know when the observer gets destroyed or are you sure it is out of the observer-list of the observed object? Interfaces with automatic destroy on refcount=0 are not an option there. (btw, you DO know that IUnknown.Release CAN be overridden to NOT Free on refcount=0?)

One might get far with a TComponent that implements attach+remove for an 2 object-instances and that implements a "visitor" pattern

TObservableEvent=class(TObject)
private
  FEmitter:
public
  constructor Create(elmitter);
  // the object that is generating the event
  property Emitter : TObject read=GetEmitter;
  procedure Execute(observer: TObject);
end;
TObserverObservableRegistry=class(TComponent)
    ...
  public
    // store a "connection" between the 2
    procedure attach(observable, observer: TObject);
    // lookup the "connection" and remove it
    procedure remove(observable, observer: TObject);
    // "loop/visit" through all the observers' oberservables and remove the "connection" where observer=parameter
    procedure removeAllObservables( observer: TObject);
    // "loop/visit" through all the observers' oberservables and remove the "connection" where observable=parameter
    procedure removeAllObservers( observable: TObject);
    // "loop/visit" over all "connections" where "observable"=event.emitter and call event.execute(connection.observer)?
    procedure fireEvent(event: TObservableEvent);
    // loop over all "connections" and remove those where connection.observer = parameter or connection.observable.parameter i.e. call removeAllObservables and removeAllObservers with that parameter
    procedure FreeNotification(...);override;
end;

In fact, TObservableEvent can be made into a referencecounted interface very easily, and I would even prefer it.

Show quoted text 6 lines
* Class Helpers like in Delphi. Also useless because you can only extend them with one helper class at a time. So you want ComboBox.Items.IsEmpty so you create a help class do do that. Now that helper class blocks any other functionality from being added. Class Helpers were introduced in Delphi 8 - the worse release of Delphi *ever*, and with such features we can clearly see why.

while I 100% agree with you on the crappyness of Delphi Ocho, I must say that it was a .Net only release! Syntax for .Net features support that later made its way into Win32 Delphi. Delphi 8 was bundled with D7 for the w32 apps.

---

that all said, I still am not opposed to design patterns, just not in something that is supposed to be somewhat delphi compatible framework.

sorry for the rambling/hard-to-follow(/read)-train-of-though, but the A/C seems broken here today in the "factory" and hot+humidity is not a way to think clearly. :-) sorry also for the conversation disruption, but I read digests on the list and can only reply accordingly.

kind regards,
Dimitri Smits

Reply by email

Luiz Americo Pereira Camara
to Michael Van Canneyt: Like I said, observe TMemo.Strings for changes. Or TObjectList: additions/removal of…
Michael Van Canneyt wrote 12 lines
On Thu, 20 May 2010, Florian Klaempfl wrote: > I've no opinion if it's usefull to add or not, I use TPersistent+ too > little but my concern is: if I create an observer for an instance, I'd > expect to get notified about every change to the instance. But I cannot > see how this will be achieved, no existing class is prepared for this? Not every change. What you get notified about is defined by the class that uses the observable interface. TStrings will notify you of additions/removals, and TList/TObjectList as well.

It will send some kind of info (like index or address of the object) to know what and where the item was added or removed?

Can the same Obsever observe (:-D) more than of one type of object? e.g. i want to observe a object list for adding or removals, but also want to know if one of the child objects changed.

(I use something like this in one of my works)

Luiz

Reply by email

Unknown author
to Luiz Americo Pereira Camara
Show quoted text 16 lines
Michael Van Canneyt escreveu: > > > On Thu, 20 May 2010, Florian Klaempfl wrote: > >> I've no opinion if it's usefull to add or not, I use TPersistent+ too >> little but my concern is: if I create an observer for an instance, I'd >> expect to get notified about every change to the instance. But I cannot >> see how this will be achieved, no existing class is prepared for this? > > Not every change. What you get notified about is defined by the class > that uses the observable interface. TStrings will notify you of > additions/removals, and TList/TObjectList as well. It will send some kind of info (like index or address of the object) to know what and where the item was added or removed?

Yes.

Can the same Obsever observe (:-D) more than of one type of object? e.g. i want to observe a object list for adding or removals, but also want to know if one of the child objects changed.

Yes. You can observe any object that will implement the IFPObservable interface.

Michael.

Reply by email

Graeme Geldenhuys
to Dimitri Smits: one of the first rules when using GoF book/patterns is: use them wisely/appropriately.…
Dimitri Smits wrote
one of the first rules when using GoF book/patterns is: use them wisely/appropriately.

Which is what we want to do.

that said, I've encountered many design pattern noobs who made it a fetish

Neither Michael or myself are new to design patterns. I for one have used them for about 10 years already.

but yet at other times unneeded.

When it's not needed, you simply do nothing (nothing observing something else) and it will be as if Observer functionality is not there - just like it is now.

ventsystem? (ISO single event handlers)

We are *not* touching the event handler system. Observer is a separate functionality and more versatile and intelligent than OnXXX events, which much less effort.

Why it has to be on TPersistent is beyond me.

Because many of the classes we want to observe descend from TPersistent. So it make sense to put the basic workings of Observer there, and then descendant components will decided what must trigger notifications.

Also we couldn't implement Observer earlier in FPC because FPC did not have the required features to do it. Now that Interface Delegation works for Corba-style interfaces, we can move to the next step.

And either way, you definately need a clean separation of concerns.

The bulk of the Observer pattern is implemented in a separate class, we than bolt that onto TPersistent via interface delegation. TPersistent will then implement the IObserverable (or whatever it will be called) interface. And not we are talking about Corba-style interface, so there is NO reference counting to worry about.

When your event occurs, you still need to call fireOpen() or fireClose() to notify

Yes, descendant classes of TPersistent will decide when notifications occur. In that even notification it will pass a reference of itself and an enum type which will give a clue as to what changed. eg: TStringList could no notification when a item text change, a new item was added or when a item was deleted.

Either way, you still need to (somehow) link back. Does your observer know it gets

Nothing will automatically observer something else. That's up to the developer to decide what they want to observer. We simply want to put the Observer functionality in place.

while I 100% agree with you on the crappyness of Delphi Ocho, I must say that it was a .Net only release!

Yes, and later it was moved to Win32 Delphi where it is still crappy.

Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Sergei Gorelkin
to Graeme Geldenhuys
Graeme Geldenhuys wrote 19 lines
Because many of the classes we want to observe descend from TPersistent. So it make sense to put the basic workings of Observer there, and then descendant components will decided what must trigger notifications. Also we couldn't implement Observer earlier in FPC because FPC did not have the required features to do it. Now that Interface Delegation works for Corba-style interfaces, we can move to the next step. > And either way, you definately need a clean separation of concerns. The bulk of the Observer pattern is implemented in a separate class, we than bolt that onto TPersistent via interface delegation. TPersistent will then implement the IObserverable (or whatever it will be called) interface. And not we are talking about Corba-style interface, so there is NO reference counting to worry about.

A word of caution:

When it comes to interface delegation, reference counting is actually the least thing to worry about, especially if delegating by class-type property. This functionality has been just introduced, and it is by no means in stable state. The most important difference from Delphi is that FPC requires that the delegate class implements the required interface by itself, while Delphi does not. Actually, Delphi delegates not the interface but its individual methods (it took me quite a while simply to realize this fact - and my patches to this part compiler were submitted *before* I realized it).
The consequences of Delphi design are just ugly: every call to a method of a delegated interface goes through the interface getter, and if getter is a function, it easily becomes top #1 in the profiler log.
While current FPC implementation does not have this ugliness, it is Delphi-compatible only to certain extent, and may change in the future. So I'd avoid to rush and rely on it in the base classes.

Regards,
Sergei

Reply by email

Graeme Geldenhuys
to Sergei Gorelkin
Sergei Gorelkin wrote
While current FPC implementation does not have this ugliness, it is Delphi-compatible only to certain extent, and may change in the future. So I'd avoid to rush and rely on it in the base classes.

I agree that your solution seems better than the Delphi implementation. As for including the Observer... it is going to go into 2.5.1 (unstable trunk) first - after all, how else are we supposed to test features if they are not activated and used. ;-)

Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email