Hacker News new | ask | show | jobs
by abid786 847 days ago
What would that practically look like? How would circular dependencies be resolved, for example?
3 comments

As far as I'm concerned, if you have circular dependencies between directories, you're doing something wrong (see also my top-level comment).

If you're sane and have a DAG of directories, you can just toposort.

In rust I have a file that defines a struct and its implementations, then I have another file that has a static array of elements of that struct. But in the struct file, one of the implementations is a TryFrom<usize>, (which is ran when you have a variable of type usize and "cast" it into my struct) this TryFrom implementation returns the value of the nth element of the static array in the second file. I don't see anything wrong in having this circular dependancy.

Potentially I could extract the TryFrom implementation into a 3rd file, breaking the circle, but tbh that feels like I'm doing that just for the sake for doing that, and it offers no real benefit.

In this case I see a benefit in keeping the struct and its implementation in a file, and another file with a static variable (which btw is around 600 lines, yeah it's a big array) in a separate file.

Don't follow rules blindly and try not to have absolute rules in your life, it'll make things simpler and more flexible.

Circular dependencies between files are fine, subject to language limitations.

Circular dependencies between directories are what's usually an indicator of something wrong.

The two usual ways I've seen it is either by following the code/control-flow (calls or inverted as called by) or by following the data flow. You can select any code function and see the call (or called) graph (shown as a tree), similarly for any data element and see the data elements that use (or is used by) graph and pruning cycles.
Call hierarchy trees usually cut cycles with a "there is already a node for this method elsewhere in the tree" end stop.
Is this meant so say it's good, bad, or just is? (which is what I meant by pruning cycles).
I'm OK with this behavior :)
Two nodes, and either two edges with one arrow each, or one edge with two arrows.

¯\_(ツ)_/¯