Inspired by YAGNI, I made this code analyzer and emacs assistant for 
deleting dead code (and then used it to delete 10% of our codebase):

https://github.com/w01fe/sniper


*Motivation:*

Over the years we've accumulated lots of dead code mixed into our 
namespaces, and getting rid of it manually is a painful job. At the same 
time, a fully automated solution won't work since there are lots of 
functions that aren't used that we want to keep.

My ideal workflow for this would be a tool-assisted, interactive loop, 
where:
 1. the tool shows the user a form that appears to be unused (except 
possibly by tests)
 2. the user decides to keep the form and marks it as used, or deletes it 
and does accompanying cleanup of the code
 3. the tool updates its internal dependency graph based on the user 
action, and goes back to (1).

I couldn't find any tools that met these criteria (and worked on our 
160KLOC codebase), so I wrote sniper.


*Features:*

Sniper understands supporting (e.g., test) forms, which behave as weak 
references, and can also identify dead code cycles (a calls b, b calls a, 
nothing else calls either) which might appear live from a local perspective.

When you delete a form, if there are supporting forms or forms involved in 
a reference cycle, sniper walks you through removing this collateral damage 
as well.

Sniper also caches the results of analysis and the set of forms marked as 
used, to make picking up where you left off easy and fast.


*Etc:*

Sniper uses clojure.tools.analyzer.jvm to analyze code.  It's an awesome 
tool, thanks to the creators/maintainers.   

There are still some classes of forms that sniper doesn't handle correctly, 
and so it will erroneously mark some forms as unused until you tell it you 
want to keep them.  

It's mostly a fun project so I don't expect it will work perfectly for 
everyone, but hopefully it's at least an interesting starting point.  

Its dependency graph may also be useful for other things.  For example, 
identifying (statically) untested forms would be very easy. 

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to