Day 4 - Excise some unused code

Well, I removed two unused methods. I’ll call that a win.

More noise than signal for me here unfortunately. In ruby from rails meta magic (like overridden to to_param), helper methods used in unscanned haml, and libraries. In java from getters/setters.

@davidw, here is what I ran to get some output from rails. This is on ubuntu with Exuberant Ctags 5.9~svn20110310 (from apt).

ctags -R
unused --ignore "public/*" --ignore "tmp/*" --ignore "app/assets/javascripts/lodash*" --ignore "app/helpers/*.rb"
2 Likes

Thanks for your help. Actually I did apt install cargo ctags-universal && cargo but it failed for me on compiling mimalloc.

I saw that there was some trickery in github actions for cross-build, then decided to try the release named linux-unknown-musl, because learning rust was totally out of scope for me today

1 Like

I had no luck with Elixir in Ubuntu. I installed unused and Universal ctags by hand.

I will make more experiments because I do not know if the tags file is being generated correctly.

Didn’t know of the existence of unused. It is very interesting.

Ran unused, had a lot of feedback. But most if not all wasn’t usable.

I may work my way through the feedback, or I just might phpstorm inspections for this

I fought with Unused and Ctags, too, and need to move on with my day. It’s too bad—I could really use these tools in my workflow. I’d love to see more concrete documentation for specific use cases. I might mess with it more, but am calling this a bust for me, for now :confused:

7 files changed, 7 insertions(+), 18 deletions(-) with Vulture (on a polyglot project), thanks @vlcinsky for the suggestion. Had time to get unused to build and run, but not enough time to go through any of the 16k tokens in 1.3k files.

1 Like

The static analysis approach is great.

In addition it has me thinking of other kinds of dead code: Fully integrated, but unused from a user standpoint.

There is a ruby project called coverband which is meant to do simplecov sampling of a running production instance. Like test code coverage, but of user’s use. Now I’m sure there are performance considerations and I also want to keep in mind seasonality, there are some things in my applications that only get used once a year; wouldn’t want to remove a key feature just because it wasn’t used during the sampling window. I’ve never used it before, but I’m inspired to try it on one of my less mission-critical applications to see.

Has anyone else used a metrics approach to finding unused-by-users code?

1 Like

Using Laravel, I’ve gone ahead and installed Nuno Maduros Larastan, which does static code analysis, fixed some type errors, and found out my app was providing a route which has never been used :smiley:

Good evening! Late to the game today too.

Found a bunch of database migration utilities we wrote years ago. I threw them all away. And with that, we’re more than 1600 lines of code lighter!

This one was tricky b/c we actually do more meta-programming in this project than I was expecting! So the unused tool found a lot of instances of methods that are not explicitly referenced but computed. However I am much more familiar with meta-programming now.

Needless to say still a massive pile of model methods that were used for some A/B test somewhere or some now deprecated feature that could get tossed out.

Yeah, I needed to install ctags first for the unused on macOS 11.2

brew install universal-ctags

then:

ctags -R --exclude=.git --exclude=log --exclude=tmp --exclude=node_modules .
unused --only-filetypes rb

But, the result was still weird :-/

2 Likes

Android Studio (by way of IntelliJ) has a very nice analysis feature that finds unused code, among other things.

I used today’s challenge to clean up a bunch of old and unused views in a Rails project. It was a great exercise!

This was the first time I used unused. It found possible hits that I’ll dig into another time. Even though I didn’t remove any unused code, I did get to start learning about a new tool.

This was super informative and thanks for sharing this!

I was able to double up with this one! The TODO that I found in the Day 2 exercise, just happened to be related to a section of code that was intended to be removed. I was able to just wipe out 38 lines :raised_hands:

Screen Shot 2021-02-06 at 11.56.47 AM

Bit late, but did this yesterday. On my dotfiles repo in Github I had a directory with a bunch of scripts that I throw into my PATH on any new machine I sit down at. Many of them have long since been replaced with other things, or are things I no longer need/use, so turfed them, PR: Remove some no longer needed utils by pzelnip · Pull Request #48 · pzelnip/dotfiles · GitHub

Seems that we have a lot of unused code floating around in our repo. Removed some but will definitely need to continue going through them over the next few weeks.

I found no unsed code. I did like exploring the unused.codes command though. fun.