Peter N Lewis wrote:
Perhaps this would be a useful thought experiment. Say I wrote a unit "WonderSound" to handle all sorts of Sound stuff, and it became wildly popular and was used by lots of folks, and so I decide to update it and add lots more functionality, and so I break the unit up in to more manageably parts, like WonderSoundInput and WonderSoundOutput and WonderSoundFilters and WonderSoundFiles etc. With Uses Propagation, I can include a unit like:
unit WonderSound;
interface
uses WonderSoundInput, WonderSoundOutput, WonderSoundFilters, WonderSoundFiles;
end.
and then all existing code works unmodified and future users can choose either to use only the unit they need, or just use WonderSound and get all the stuff.
This would be close to something I have in mind as "libraries" (not implemented yet, maybe BP or Delphi compatible, don't remember exactly), i.e. basically one unit/library as a "container" for several units. (Whether there may be additional declarations in a library, if it's Borland compatible, I don't know -- but at least in your example this wouldn't seem crucial.)
Please note I'm not advocating Uses Propagation as something that has to go in to GPC, just trying to clarify where it might be useful. There is certainly a good case to be made against uses propagation, and I think I'd rather see some sort of extension to allow this to be used where appropriate, perhaps something like a synonym for "uses" that also reexports the listed units, or perhaps something like "uses WonderSoundInput (reexport);" or perhaps in the style of "external", something like "uses WonderSoundInput; reexport;"
A new syntax would surely help to distinguish it from the rest. OTOH, new syntax rules always introduce complexity in the parser. If we're to design it on our own (no compatibility concerns), we should at leastt try to keep the complexity as low as possible:
- new keyword (synonym for `uses'): not if it can be avoided at all (see my other mails)
- `uses ...; reexport;': prone to parser difficulties. Reason: After the first ';', the uses statement might be finished -- or it might not be, with the new syntax. So the new syntax can potentially conflict with anything that's valid after a uses statement (which includes many possible future extensions).
- `uses ... (reexport);' seems more harmless (rather strict syntactic context, fewer chances for conflicts). It would still add a ("weak") keyword, though. ("Weak" meaning that it is well separated from identifiers, so it can in fact be parsed as an identifier, AFAICS.) Not too much of a problem, but it adds to the list of special identifiers ...
An alternative could be the use of some symbols instead of new keywords (but I don't have a good idea for this yet), or a combination of keywords, such as `uses external ...' or `uses export ...' or `export uses' etc. (just playing around with words ... ;-).
although that would really require allowing multiple "uses" statements to allow for some that were reexported and some that were not.
Which GPC does (non-standard, non-BP, but we're talking about extensions here, anyway ...)
CBFalconer wrote:
Things might NOT be compatible. A provision of units, at least under Borland, is that they have (possibly empty) initialization code, which is automatically called at program initialization time. I don't think such would occur here.
It would -- that's not the problem. Also indirectly used units are initialized (the initializers of one unit call those of the ones they use, and each identifier has a flag so it's not run twice).
Frank