Hacker News new | ask | show | jobs
by pjmlp 1036 days ago
> The no-circular-dependencies rule was a huge pain though. It allowed the compiler to be very fast (along with it basically not optimizing), but no other language has copied this

C++20 Modules, .NET Assemblies, D modules, Ada packages, and plenty of other othes.

Also, Turbo Pascal did indeed allow for circular dependencies between units, as long as the related uses statements were written in the implementation section of the unit, and there were no public dependencies.

Thanks to bitsavers, Turbo Pascal 5 manual, page 97,

http://bitsavers.informatik.uni-stuttgart.de/pdf/borland/tur...

3 comments

Yeah, this... You can have circular dependencies, as long as it is in the implementation only. Takes some thought on interface definitions to avoid these things. Sometimes it's a real pain.

There's also the issue that when you split out units, and then you have a user who wants to consume say, a library you've written, you then have to document "Ok, to use this you have to use X, Y, and Z units for type definitions"

A better approach is to have a single "entry point" unit if you will, that simply re-declares all of the types from the X,Y,Z units, so that when you go to use the code you've written, you only have to import W, and get all the type defs already. (Hard to explain what I'm talking about I guess)

IIRC, pre-Object Pascal Pascals had a "forward" declaration using which you could call a function or procedure before defining it, as long as it was defined somewhere below in the program. I don't remember if it supported circular dependencies or not.
Modules and assemblies are different. Lots of languages ban circular dependencies between modules (most!). Delphi units were single source files though, and that's a much more painful proposition because it forcibly links source file size and program architecture. I saw a lot of big unit files in Delphi code bases.
Arriving at a place with a Delphi codebase developped over the course of 30 years (some files had 80ies copyrights), the tendency tot have enormously long ones was apparent. 10k lines would be short, and 100k nothing unusual. Really hard tot navigatie, the Delphi IDE doesn't really help with that (or much else really).
Apparently no one read the part about dependencies being allowed between implementations section, and I imagine also never looked into Delphi packages, in regards to code size and organising units.
I recall being allowed to have dependencies between implementation sections, but this was still quite a painful restriction.

I don't remember Delphi packages, indeed. It was a long time ago now.