Lazarus

Free Pascal => General => Topic started by: guest65405 on March 29, 2020, 07:23:04 pm

Title: Units
Post by: guest65405 on March 29, 2020, 07:23:04 pm
I have a bunch of units and I want to include them all into a big unit. This is what the C library does, it has a header whose content just include other headers.

Would the same way work with Pascal? So when I use the big unit all of the small units are available to me? Or have I need to use $I to actually include all of the small units?
Title: Re: Units
Post by: Jonas Maebe on March 29, 2020, 08:00:41 pm
It is not possible to propagate the interfaces of units through other units that use them.

Including them all in a different unit is possible (if you take care with ifdefs that you don't end up with multiple interface/implementation sections etc), but this will cause problems if both this big unit and the individual units are used in the same problem. The reason is that Pascal types generally do not use structural equivalence (unlike C types), and hence structured types identically declared in the big unit and in the small units will be incompatible.
Title: Re: Units
Post by: 440bx on March 29, 2020, 08:13:11 pm
I have a bunch of units and I want to include them all into a big unit. This is what the C library does, it has a header whose content just include other headers.
That's a terrible idea.  One of the many problems in C is the lack of modularity and the need to have headers include other headers that include the headers that were already included someplace else.  It's pedestrian, baroque, and resembles the path a drunkard takes to get home. 

Would the same way work with Pascal? So when I use the big unit all of the small units are available to me? Or have I need to use $I to actually include all of the small units?
It might work but, it's a little bit like having a gun and asking someone if you can shoot yourself in the foot with it.  Odds are the answer is "yes" but, the question raises concerns about the mental stability of the individual asking it.

(Modern) Pascal is modular and organized, C is neither.  You don't want to import C's mess into Pascal.
Title: Re: Units
Post by: Otto on March 29, 2020, 11:25:08 pm
Hello 440bx
I agree FPC is well organized.

A short time ago I opened a thread on a topic in a somewhat related way. The main topic is the ability to use PartialUnits (https://forum.lazarus.freepascal.org/index.php/topic,48882.60.html#msg354961), which consist of a single unit fragmented into distinct parts of code. It also discusses the opposite argument for merging (https://forum.lazarus.freepascal.org/index.php/topic,48882.msg352848.html#msg352848) multiple separate Units (thanks to soerensen3), that is the arguments of this thread.

Otto.
TinyPortal © 2005-2018