[Lazarus] Circular references and code quality

Marcos Douglas md at delfire.net
Tue Oct 4 16:40:34 CEST 2011


2011/10/4 Juha Manninen <juha.manninen62 at gmail.com>:
> Hi
> There is lots of duplicate code and data definitions between Lazarus
> TProject and TLazPackage (and their ancestors).
> I tried to improve the situation by creating a common base class for them.
> It is not possible because it ends up with a circular reference hell.
> Almost 2 years ago I suggested to solve the problem in language syntax
> somehow.
>   http://lists.freepascal.org/lists/fpc-devel/2010-January/018909.html
> The comments always tell to use interfaces and abstract base classes, and
> claim that this feature enforces good design.
> Bollocks!

I agree with you.
I found this example by Nikolai ZHUBR:
http://lists.freepascal.org/lists/fpc-devel/2010-January/018942.html
I do not think this is better solution. For only one "circular
reference" between 2 classes, I have to created 3 files! And if these
references grow?!

> This feature enforces BAD design and implementation. Lazarus itself is an
> example of it.
> Is copy-pasting code between Project and Package a sign of good design. IMO
> it is not.
> Is the class structure somehow flawed if such problems happen. No it is not.
> Such things happen in big, real projects.
> For the same reason there are many type-casts in Lazarus core units. A
> variable is type-casted from base class to the real class.

These "base classes" with many virtual methods empty or raising
Exceptions is, IMHO, bad design implementation too.
These classes just exists to do the magic of polymorphism works...
where the many many copy definition methods codes was the price.

> Another common solution is to copy all code into one big file. It is not
> only a bad thing but it has some limits. You wouldn't want to copy most
> Lazarus code into one file for example.
> Thus I found it strange that even Lazarus developers claimed they never
> encountered such problems. Yet, they have clearly worked hard to avoid
> circular references.

Florian Klaempfl said more options here:
http://lists.freepascal.org/lists/fpc-devel/2010-January/018948.html
They are:
- abstract base classes = I said about them...
- interfases = doubles the code many many times, just to work around
the circular reference
- include files = doubles the code physically
- big units = hard to read...
- type casting (in the worst case) = yeah, the worst case...


> It is almost like in a religious sect, nobody dares to admit it was a
> mistake to join it.
> I read the Bold application has abandoned Delphi native code and moved to
> .NET.
> The reason was mostly circular reference problems, which I understand with
> such object framework tool.
> I am not expecting any solution for this now. Even the latest Delphi has not
> solved it although it has many other syntax additions.
> I just feel strongly that the language will remain a niche, not interesting
> for most people, because of this one single problem. Pretty much all other
> features are good.
> Pity!
> I remember already years ago someone told me he used Delphi but it was not
> suitable for big projects because of circular reference problems, and he
> moved to other languages.
> Then I didn't understand how serious the problem is but I learned it later.
> If someone still wants to claim that there is absolutely no problem, please
> show me how to reuse code between Lazarus Project and Package thus avoiding
> the duplicate code, without copying most Lazarus code into one unit.
> Then I will believe there is no problem.
> Or, explain me why it is a good thing to have all those type-casts in
> Lazarus core-units (connecting to Designer etc.).
> Sorry for this rant. I like to solve problems but there is no way to solve
> this one, except for changing the language. Frustrated now...

Marcos Douglas




More information about the Lazarus mailing list