3 ms·
The simplest case where I'd want a circular dependencies is I have a module that defines some data types and functions on those types mod widget struct Wi
by edflsafoiewq 6y ago
The simplest case where I'd want a circular dependencies is I have a module that defines some data types and functions on those types
mod widget
struct Widget
fn show(Widget) { ... }
fn join(Widget) { ... }
fn calc_box(Widget) { ... }
and one function is getting very long and complicated so I want to spin it out into its own module
mod widget mod calc_box
import calc_box from widget import Widget
struct Widget fn calc_box(Widget) { ... }
fn show(Widget) { ... }
fn join(Widget) { ... }
The reason the article gives that this is "evil" is that there is no hierarchy between the modules; the cycle is really just one big supermodule. That's true... but that was basically the point. Where is the "evil" here?
- vasergen 6y agoIn that case you can separate ’struct Widget’ into another file. This way there will be no circular dependency
- edflsafoiewq 6y agoI know how to break the cycle. What I'm asking is why should I break the cycle?
- vasergen 6y agoIt depends on situation. As an example, it could be difficult to write tests when you have circular dependency. As well depends on the language there could be strange ’side effects’ which would be difficult to debug.