Something that's bothered me for a while I wanted to ask about.

I have a package I want to distribute which has 2 or more units, all of which 
are required to use the package. Technically all the code should be in one file 
but because units are a nice feature of Pascal we like to keep our code 
separate when we develop.

Usually what happens is we compromise and do either:

1) Have the user of the package add all the units to the uses clause of every 
file which needs it. This is annoying for the user because it bloats the uses 
section but for the developer our code is nicely separated into units.

2) Break the units into include files and wrap the interface/implementation 
blocks in ifdefs. This is nice for the user because they only have a single 
unit to use but now the developers of the package have to work in what are 
essentially header files (like in C). The RTL is of course filled with examples 
like this.

It feels to me like Pascal is missing a way to have the compiler help you make 
these "umbrella" units so we default back to C-like techniques which we've been 
using since the 90's.

I see things like this from other newer languages and it seems like something 
Pascal should have given the already existing module structure we take for 
granted but languages like C don't have.

unit test;

imports
  (A, B, C) from SomeUnit, OtherUnit; // types/functions are imported into the 
unit and accessible from the outside

end.

Any ideas of solutions or preferred approaches? Is it feasible to add an 
"imports" clause to Pascal or are there other pitfalls?


Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to