From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thorsten Jolitz Newsgroups: gmane.emacs.help Subject: Re: Circular dependencies between libraries - what to do? Date: Sun, 21 Sep 2014 12:37:51 +0200 Message-ID: <8761gh6yyo.fsf@gmail.com> References: <87d2aqgf92.fsf@gmail.com> <88832444-184c-4cbd-8147-1114b5e78dcb@default> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1411299642 16034 80.91.229.3 (21 Sep 2014 11:40:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 21 Sep 2014 11:40:42 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Sep 21 13:40:34 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XVfVK-0003dw-9k for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Sep 2014 13:40:34 +0200 Original-Received: from localhost ([::1]:38921 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVfVJ-00072X-V2 for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Sep 2014 07:40:33 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54312) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVfSl-000388-40 for help-gnu-emacs@gnu.org; Sun, 21 Sep 2014 07:38:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XVfSe-0002r4-I2 for help-gnu-emacs@gnu.org; Sun, 21 Sep 2014 07:37:55 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:35554) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVfSe-0002pu-BE for help-gnu-emacs@gnu.org; Sun, 21 Sep 2014 07:37:48 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XVeWu-0002Pm-QQ for help-gnu-emacs@gnu.org; Sun, 21 Sep 2014 12:38:08 +0200 Original-Received: from g231232138.adsl.alicedsl.de ([92.231.232.138]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 21 Sep 2014 12:38:08 +0200 Original-Received: from tjolitz by g231232138.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 21 Sep 2014 12:38:08 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 74 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: g231232138.adsl.alicedsl.de User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:5EVlEyKJvSQ1WAa07VQse8Hio3U= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:100096 Archived-At: Drew Adams writes: >> 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). I ckecked my libraries and figured out that I actually mixed up two kinds of dependencies (ignore the names, I just made them up): - 'technical dependency' -> lib A calls lib B's functions - 'functional dependency' -> lib A won't work on a buffer if lib B hasn't been activated in other words, outshine.el requires outorg.el because it calls its functions, but outorg.el only needs outline-minor-mode with outshine extensions loaded to work, it does not technically require outshine functions. So I could actually distribute the (require ...) calls in a sane way over the libs and solve the issue. Thanks for the tips anyway, I will keep them in mind. PS I wonder why my announcement of Outshine 2.0 did not make it to this list - thats like an 8h delay or so. -- cheers, Thorsten