Hello David,

While I appreciate an articulation of best practices, I confess I've never
been bitten by trouble with circular dependencies. However, I also never
export constants, and it might be the case the constants declared among a
collection of modules, and used among multiple of the same modules, could
lead to errors. However, I can think of two distinct strategies for
handling this that would alleviate the issue without sacrificing the
utility of circular dependencies.

Before I go down that rabbit hole, though, perhaps you could shed some
light on the kind of problems you've encountered before. Do you have any
publicly visible projects in which circular dependencies caused headaches?

Thanks!
David

On Tue, Oct 18, 2016 at 5:00 PM, David Christensen <
dpchr...@holgerdanske.com> wrote:

> On 10/17/2016 11:05 PM, David Christensen wrote:
> > I have applied a hierarchical module dependency architecture to avoid
> > circular dependencies:
> >
> > 1.  Modules and test scripts that do not depend upon any other
> > modules within the distribution are "dependency level 0".
> >
> > 2.  Modules and test scripts that depend only upon level 0 modules
> > are level 1.
> >
> > 3.  Modules that depend only upon levels 0 through N are level N+1.
>
> Pondering this some more, here is a more accurate statement of the
> strategy I have been using to avoid circular dependencies within
> distributions (revised rules marked with '*'):
>
> 1.  Modules that do not depend upon any other modules within the
> distribution are "dependency level 0".
>
> *2.  Modules that depend only upon modules of levels 0 through N-1 are
> level N, for levels N=1 and higher.
>
> *3.  Module test scripts shall not depend upon modules of higher level
> than the module they are testing.
>
> *4.  Test scripts shall be run in order from lowest to highest level.
>
>
> It's rule #3 that has been giving me the most trouble.  For example, I
> have testing modules up to level 5 that I would like to use when testing
> modules of level 0-4.  Rule #3 blocks me.
>
>
> As I code my test scripts with no outgoing dependencies -- e.g. I do not
> 'use' or require' test script files in other files -- test scripts
> cannot create circular dependencies.  The fact that they are named after
> a particular module is for my benefit; but accidental as far as the
> tools are concerned.  The file name of a test script has no bearing upon
> its dependency level.
>
>
> So, perhaps rule #3 should be revised.  Here is the proposed strategy:
>
> 1.  Modules that do not depend upon any other modules within the
> distribution are "dependency level 0".
>
> 2.  Modules that depend only upon modules of levels 0 through N-1 are
> level N, for levels N=1 and higher.
>
> *3.  Test scripts have a level equal to the highest level module they
> depend upon.
>
> 4.  Test scripts shall be run in order from lowest to highest level.
>
>
> I would then write multiple test scripts for each module -- "early" test
> scripts of the same level as the module under test and "late" test
> scripts that depend upon higher level modules.
>
>
> Comments are welcome.
>
>
> David
>



-- 
 "Debugging is twice as hard as writing the code in the first place.
  Therefore, if you write the code as cleverly as possible, you are,
  by definition, not smart enough to debug it." -- Brian Kernighan

Reply via email to