[fpc-devel] Circular references and forward declarations

Nikolai ZHUBR zhubr at mail.ru
Wed Jan 6 14:56:16 CET 2010


Wednesday, January 06, 2010, 2:47:24 PM, Juha Manninen wrote:

> On keskiviikko, 6. tammikuuta 2010 13:14:18 Michael Van Canneyt wrote:

>> Why ? Every class in 1 file is perfectly possible with include files, and 1
>> big unit file.

> Ok, include files seem to solve this problem.
> I don't know why they are not commonly used in Delphi programs as source

I don't like include files and try to not use them anywhere except
in some cross-platform libraries, along with conditional compilation,
and even then, I always try to minimize them.

An include file by its pure nature is just an arbitary fragment. It
does not necessarily have any consistent meaning on its own, either
logically or syntactically. Therefore, compiler does not (and have
no way to) do any integrity/dependancy checking on include file as
on a separate entity. For the same reason, looking at an include file
may give absolutely no idea of its meaning unless you also open all
its including files along with.

The concept of include files is not part of the language. It is just
a tool to mitigate the troubles of editing/storage/archiving and
such other maintenance burden tasks. From the language perspective,
include files just do not exist! They are substituted textually, just
like copy-n-paste, effectively producing one (big or not, whatever)
file anyway. Period.

On the other hand, object pascal as a language offers 2 mechanisms
for structuring code logically: units and classes. Both are
language concepts, both allow compiler to actively help programmer
by means of visibility restrictions etc. I would say, some corner
cases do exist, where the concept of units and the concept of classes
somehow clinch in unconfortable manner. IMHO this does not happen
too often and there are some known workarounds. Still probably,
the language in its current form has its limits. Maybe these could
be extended eventually, at least "out of academic curiosity". In
practice however, object pascal already provides such benefits that
it is imho quite fair to tolerate some corner rough edges.

Nikolai ZHUBR

> files. It may be a culture or convention also, technically it should be 
> possible with Delphi as well.
> I must change my mindset for those include files.


> Juha Manninen
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel





More information about the fpc-devel mailing list