Cyclic dependency in Go ?

455 views
Skip to first unread message

ziyu_huang

unread,
Dec 6, 2009, 11:41:36 AM12/6/09
to golang-nuts
What if your package have cyclic dependency.
How to compile or link in Go ?
Or this issues is just leave to user ?

msw

unread,
Dec 6, 2009, 11:52:09 AM12/6/09
to golang-nuts
I would think - in any programming language - if it is confusing or
impossible to compile, it will be even harder for a human to
understand. Can you give an example of where you might require cyclic
dependencies? I'm guessing that any such code could be reorganized to
eliminate the cycle.

(no, I didn't answer the question that you asked,)

Russ Cox

unread,
Dec 6, 2009, 11:58:39 AM12/6/09
to ziyu_huang, golang-nuts
On Sun, Dec 6, 2009 at 08:41, ziyu_huang <ziyu4...@gmail.com> wrote:
> What if your package have cyclic dependency.

If you have a cyclic dependency between files
within a single package, that's fine.

If you have a cyclic dependency between packages,
that's not: it won't compile and you have to fix your
packages to eliminate the dependency. This is occasionally
annoying but has much better scaling properties
than allowing cycles: it means you're guaranteed
you can compile each package by itself (after compiling
its dependencies).

Russ

ziyu_huang

unread,
Dec 7, 2009, 1:11:43 AM12/7/09
to golang-nuts
Hi Russ,

Thanks Russ, I complete agree with you. I just have doubt because I
try to write a auto make program for Go.
http://code.google.com/p/moogle-store/
I think I will detect cyclic decency and stop make that problematic
package.

In C/C++, it just throw cyclic dependency issues to linker and let
linker decide how to solve it, and it may works something and fail
later.
So we won't detect that problem in early stage.

Since Go have excellent package system and don't provide header, it
will raise the problem in compile time rather then link time.
This is good approach, IMO. :) Stop people do stupid


On 12月7日, 上午12時58分, Russ Cox <r...@golang.org> wrote:
> On Sun, Dec 6, 2009 at 08:41, ziyu_huang <ziyu4hu...@gmail.com> wrote:
> > What if your package havecyclicdependency.
>
> If you have acyclicdependencybetween files
> within a single package, that's fine.
>
> If you have acyclicdependencybetween packages,
> that's not: it won't compile and you have to fix your
> packages to eliminate thedependency.  This is occasionally
Reply all
Reply to author
Forward
0 new messages