help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Circular dependencies between libraries - what to do?


From: Drew Adams
Subject: RE: Circular dependencies between libraries - what to do?
Date: Sat, 20 Sep 2014 18:52:59 -0700 (PDT)

> I have libraries that depend on each other, and I'm not sure
>  (1) how to use require without introducing circular dependencies?
>  (2) how to declare their dependencies as MELPA packages?
> 
> 1. When I put in
> ,----
> | A
> | (require 'B)
> `----
> and in
> ,----
> | B
> | (require 'A)
> `----
> 
> I'm probably asking for trouble, but B actually does not work
> without A, and A calls B functions, so they do require each other.

If these are your own libraries, so that you can modify their code,
then break them into pieces, and then reorder and recombine pieces.

Here is the guiding principle:

  It is not *all* of A that requires *all* of B, and
  it is not *all* of B that requires *all* of A.

So look at the code carefully and find which pieces have hard
(i.e., logical) dependencies on which other pieces.  Keep pieces
that must be together together; separate (at least logically and
temporarily) things that can be separated.

When you have something that makes sense, and thus works, then
you can try combining pieces to end up with fewer and larger
ones.  You might find that you end up with more than two files.
Or you might find that you end up with only one file, but
better structured (e.g. reordered).

You will have, at least during the exercise, made any real
dependencies explicit.  You will understand your code better,
and you will make it easier to modify it in the future.

Yes, this can take some time.  Two aids are:
1. The byte-compiler, as others have mentioned.
2. Commenting-out sections of code temporarily, using, e.g.,
   `comment-region' (with `C-u' it uncomments).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]