Fork me on GitHub
#admin-announcements
<
2015-12-24
>
seancorfield04:12:52

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.

seancorfield04:12:38

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

cjmurphy04:12:31

@seancorfield: If it is Java classes files there are many. I have used DependencyFinder (http://depfind.sourceforge.net/). 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.

seancorfield04:12:05

Not JAR dependencies. Source file dependencies in Clojure.

cjmurphy04:12:28

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

seancorfield04:12:09

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

seancorfield04:12:21

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.

cjmurphy04:12:55

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

seancorfield04:12:14

As I said, not what I want.

seancorfield04:12:25

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

seancorfield04:12:54

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

cjmurphy04:12:33

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

seancorfield04:12:18

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

seancorfield04:12:49

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.

seancorfield04:12:57

Hmm, yeah, dependency graph looks promising.

seancorfield05:12:37

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

cjmurphy05:12:44

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.

cjmurphy05:12:04

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

seancorfield05:12:38

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

seancorfield05:12:52

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).

cjmurphy05:12:01

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.

seancorfield05:12:46

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...

meikemertsch05:12:24

@seancorfield: this one is pretty crude but maybe you can start there: https://github.com/hilverd/lein-ns-dep-graph is that the kind of tool you're looking for?

pvinis05:12:28

https://shaunlebron.github.io/parinfer/ wow that looks seriously interesting to me as a beginner

seancorfield05:12:50

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

seancorfield05:12:42

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!

meikemertsch05:12:11

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

seancorfield05:12:09

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

seancorfield05:12:06

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

meikemertsch07:12:06

Sir? ;) My pleasure

malch07:12:52

@seancorfield: You may want to take a look here: https://github.com/Hendrick/boot-medusa

seancorfield07:12:28

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

seancorfield07:12:49

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

malch07:12:06

Just for your information, np šŸ˜‰

malch07:12:51

@seancorfield: Also Iā€™m using https://github.com/greglook/lein-hiera in lein world