On Jun 10, 2022, at 8:47 PM, jlfo...@berkeley.edu <jlforr...@berkeley.edu> 
wrote:
> 
> One hack solution I came up with to break cycles when Package A depends on 
> Package B which depends on Package A is to
> create a symbolic link in Package A to the file(s) in Package B that 
> contain(s) the resources needed by Package A. Then Package A
> wouldn't be dependent on Package B anymore, and the cycle will  be broken. (I 
> just thought of this so I'm not 100% sure it will work
> until I try it).

You can factor out the mutually dependent functions in a separate package. For 
example if p1.P calls p2.P and p2.P calls p1.P,
create package p3, move p1.P and p2.P into p3 and rename them to p3.P1P and 
p3.P2P respectively.

> To tell the truth, the requirement that all files in a package be in the same 
> directory will probably cause the most misery. The program I'm
> trying to port has so many subdirectories containing so many files that this 
> will be a big problem. I'm thinking now that I'll have to move all the files
> in a package tree to the top level directory, and use a naming scheme so that 
> I can see which subdirectory each file came from.

You can start by simply treating each subdir as a package and then once things 
start working, refactor everything. The key is to either do refactoring up 
front or after you have a working, testable implementation, even if imperfect.

Another alternative is figure out major subsystems and data structures and 
create packages around them, adding many tests so that you can test each 
package in isolation.

Yet another alternative is to simply treat the existing app as a *reference* 
and nothing more. That is, rebuild your app in Go from scratch, simply based on 
the input/output behavior of the original app. But if the app is large and 
complex this may not be the best option. On the other hand I wouldn't want to 
convert a large and complex app to a different language, unless it can be 
broken up in smaller pieces relatively cleanly.


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/7AB0D4AB-F517-431E-822E-8647C12ECB9A%40iitbombay.org.

Reply via email to