From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: Circular dependencies between libraries - what to do? Date: Sat, 20 Sep 2014 18:52:59 -0700 (PDT) Message-ID: <88832444-184c-4cbd-8147-1114b5e78dcb@default> References: <87d2aqgf92.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1411264429 8516 80.91.229.3 (21 Sep 2014 01:53:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 21 Sep 2014 01:53:49 +0000 (UTC) To: Thorsten Jolitz , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Sep 21 03:53:41 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 1XVWLL-0003cF-Aw for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Sep 2014 03:53:39 +0200 Original-Received: from localhost ([::1]:37549 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVWLK-00028c-Ok for geh-help-gnu-emacs@m.gmane.org; Sat, 20 Sep 2014 21:53:38 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVWL2-00028W-6f for help-gnu-emacs@gnu.org; Sat, 20 Sep 2014 21:53:28 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XVWKt-0000VR-G1 for help-gnu-emacs@gnu.org; Sat, 20 Sep 2014 21:53:20 -0400 Original-Received: from userp1040.oracle.com ([156.151.31.81]:49698) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVWKt-0000UW-9j for help-gnu-emacs@gnu.org; Sat, 20 Sep 2014 21:53:11 -0400 Original-Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s8L1r21N012467 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 21 Sep 2014 01:53:03 GMT Original-Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s8L1r1Zr002092 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 21 Sep 2014 01:53:02 GMT Original-Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s8L1r1EV002086; Sun, 21 Sep 2014 01:53:01 GMT In-Reply-To: <87d2aqgf92.fsf@gmail.com> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.8.2 (807160) [OL 12.0.6691.5000 (x86)] X-Source-IP: acsinet21.oracle.com [141.146.126.237] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 156.151.31.81 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:100083 Archived-At: > 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? >=20 > 1. When I put in > ,---- > | A > | (require 'B) > `---- > and in > ,---- > | B > | (require 'A) > `---- >=20 > 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).