Hacker News new | ask | show | jobs
by o11c 848 days ago
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.

1 comments

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.