# Circular dependency?

**URL:** <https://discourse.julialang.org/t/circular-dependency/35571>\
**Category:** General Usage\
**Created:** [March 5, 2020, 11:43am UTC](https://discourse.julialang.org/t/circular-dependency/35571 "2020-03-05T11:43:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Post date:** [March 5, 2020, 11:43am UTC](https://discourse.julialang.org/t/circular-dependency/35571/1 "2020-03-05T11:43:40Z")

</div>

if I have two modules `A` and `B`, where `A` needs `using B` and `B` needs `using A`.  
would it cause problem? if there is, how could I solve it? thanks. 🙏

---

<div class="post-metadata">

**Author:** ![zgornel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zgornel/32/217487_2.png) [@zgornel](https://discourse.julialang.org/u/zgornel)\
**Post date:** [March 5, 2020, 12:29pm UTC](https://discourse.julialang.org/t/circular-dependency/35571/2 "2020-03-05T12:29:57Z")

</div>

Unite into single module or move common functionality in a third module `C`. A circular dependency should more often than not viewed as a design flaw more than an issue to be handled explicitly.

---

<div class="post-metadata">

**Author:** ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Post date:** [March 5, 2020, 2:31pm UTC](https://discourse.julialang.org/t/circular-dependency/35571/3 "2020-03-05T14:31:47Z")

</div>

that means there’s no shortcut except to figure out the sequence of module dependencies 🙁

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [March 5, 2020, 9:41pm UTC](https://discourse.julialang.org/t/circular-dependency/35571/4 "2020-03-05T21:41:36Z")

</div>

A different perspective is that it’s a very good opportunity to refactor the code to a better design so you can maintain it more easily going forward.

---

<div class="post-metadata">

**Author:** ![joshua\_jones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshua_jones/32/7554_2.png) [@joshua\_jones](https://discourse.julialang.org/u/joshua_jones)\
**Post date:** [March 6, 2020, 1:37am UTC](https://discourse.julialang.org/t/circular-dependency/35571/5 "2020-03-06T01:37:35Z")

</div>

> [@tomtom](#):
>
> if I have two modules `A` and `B`, where `A` needs `using B` and `B` needs `using A`.  
> would it cause problem? if there is, how could I solve it? thanks. 🙏

a. Yes.  
b. Depends on preference and how closely related the purposes are of A and B. One strong option is what @zgornel and @tk3369 said. Personally, if I had two interdependent modules, I’d place their common code in one module (let’s call it C), then move the unique parts of A and B to two submodules, C.A and C.B. Then I could play around with import/export/using until the project is clean enough that others can easily follow my steps.
