Fork me on GitHub

Is there a tool for printing out a namespace dependency tree? Looking to refactor our code base and want to idea which pieces we easily pull out into sub-projects.


(It feels like something that could easily be built but I figured I'd ask before I reinvent that wheel)


@seancorfield: If it is Java classes files there are many. I have used DependencyFinder ( IntelliJ is also really good (although it may work with sources files). Of course none of this helps with ClojureScript. One of the reasons DependencyFinder is good IMO because it goes off Robert C. Martin's metrics, and it is easy to find the recursive namespace dependencies which are the worst thing.


Not JAR dependencies. Source file dependencies in Clojure.


They all become class files though, these tools would not know how the classes were produced, DependencyFinder anyway.


No, that's not what I want. I want to analyze source code for the namespaces that are required to create a tree.


Worst case, I can write something to parse the code, read the ns / :require forms, and build a tree. I was just hoping something already existed.


It analyses class files but what it gives you is namespaces and how they are related to one another (i.e. Java imports).


As I said, not what I want.


I don't care about dependencies outside the source tree.


I only care about internal dependencies in the source code of one project.


Yep - it basically does what would be called 'package dependencies' in the Java world, which are 'namespace dependencies' in this world.


You're not being much help but I appreciate the effort simple_smile


I'll go look in tools.namespace -- I suspect it knows how to build a tree since it can do a reload in namespace dependency order.


Hmm, yeah, dependency graph looks promising.


(fwiw, we don't AOT our Clojure so there are no class files on disk and we don't create a JAR either)


These tools give you your DAG - a neat diagram so you can understand your design. It is fairly OO stuff but my thinking it that it still applies.


Oh no class files. That no good at all! šŸ˜ž


Hence my wanting something either source-based or that I can use from the REPL fairly easily... simple_smile


We have about 30,000 lines of Clojure in production and we're moving from Leiningen to Boot so we have an opportunity to move away from a rigid project-based structure to something more modular (one of the things that Boot is intended to help with).


I do a special build to exclude 'not done by us' library dependencies, so the DAG (directed acyclical graph) output is concentrating on only the actual production code we wrote. But I haven't needed to do this stuff with Clojure yet, and DependencyFinder is pretty old now. It is a very interesting and important area - good to keep tabs esp on recursive namespace dependencies (and uncle Bob's metrics) while any largish project is ongoing. However that is all my old OO thinking. I'm not so sure the metrics would be so important in a functional design.


Yeah, I used to do a lot of OOP metrics and source code analysis work back in the early/mid-90's. I wrote a C++ source code analyzer that did a whole bunch of stuff around coupling and coherence. It's been a long time so my OOP metrics memory is probably a bit rusty now...


@seancorfield: this one is pretty crude but maybe you can start there: is that the kind of tool you're looking for?

pvinis05:12:28 wow that looks seriously interesting to me as a beginner


@meikemertsch: Great! Sounds like it'll save me a bunch of work...


I guess I'll need to take it apart to produce just a text tree... I don't really want a picture since that's not so easy to manipulate... but it should get me started!


I found that and a similar one a couple of months back by looking for namespace dependency lein šŸ˜‰


Guess I should build a Boot task for it since that's the way I'm going these days...


Much appreciated @meikemertsch -- I have a Boot task now that produces a first cut text dependency graph of my code! Thank you sir!


Sir? ;) My pleasure


@malch: produces a picture like lein-ns-graph. Not easy to manipulate. But thank you anyway.


Good to know that I'm not crazy in wanting a tool like this!


Just for your information, np šŸ˜‰