Our codebase is mostly C and C++, so I used cppcheck --enable=unusedFunction
. Cppcheck found two related functions, which I deleted along with their global state(!). Unfortunately, since this codebase makes heavy use of function pointers (stored in arrays as part of a custom parser), cppcheck gives many false positives. I also tried callcatcher, but had a similar issue with false positives. I didn’t try Unused. Anyone succeed in using it on a C/C++ codebase?
I’m trying to get unused ready on Debian, but I’ve run into trouble. After installing haskell-stack
(from sid) and running stack update
, I tried stack install unused
, but I errors with this message:
AesonException "Error in $.packages.cassava.constraints.flags['bytestring--lt-0_10_4']: Invalid flag name: \"bytestring--lt-0_10_4\""
Any ideas?
Looks like some Haskell version hell on Debian Buster/Sid is blocking that option, but the docker option seems to have worked…
But after all that, I get Unused found no results
. It looks like it’s analyzing my code for 2084 terms, but I added a uniquely named method to one of the models, without calling it from anywhere… it then said 2085 terms, but still 'Unused found no results`. So something must be going wrong here.
+20 -100
Mmmm trying to remove unused code I had to add some lines
I’m going to have to revisit this one—I’m pretty good about spotting unused code during feature work, but we don’t have tooling in place to find code for us. I had trouble with unused because I need to upgrade Xcode first, and that won’t happen today.
Instead, I installed the SimpleCov gem, and got it configured for this app running locally. We usually run the full suite on Jenkins, though, and that’s going to require some additional configuration.
I also struggled with C code base. I did see that Unused should theoretically work with C/C++ code as long as you set up the ctags for it but I ran out of time… one more thing for my TODO list I did received some other style suggestions while running the cppcheck (thanks @nwalton!) that I’ll review later.
Make sure your ctags file is in your .gitignore, otherwise it will see it as a code file and think your unique method is being called there. Ref.
It looks like I am not alone in finding this to be a trickier challenge than the others.
I kept running into the following error:
Unused: analyzing unused: ./tags: hGetContents: invalid argument (invalid byte sequence)
Eventually, I got it to work after updating how I generated my ctags
to only look at ruby
with:
git ls-files | xargs ctags --language ruby
The results were mostly pointing me at specs and cassettes.
However, I did see an _test
file which stuck out since we use rspec
and would normally see _spec
. This test was generated from a feedback plugin we have in our application that hasn’t been used since December 2014. I have put together a PR to start a conversation with the team about whether it provides any benefit at this point. If it gets merged, I will be +0/-1,258
for this challenge !
Oh wow, what a day.
“Unused” gave me a couple leads, but https://github.com/flyerhzm/rails_best_practices turned up WAY more good stuff. WARNING: I would not recommend trusting that gem - it finds a lot of false positives! However, it’s extremely thorough & permissive with what it returns on a Rails app, and it put everything in a format I could quickly browse over.
I ended up being able to delete 5 whole scaffolded-out models (including DB tables) that have been sitting unused for 2+ years in our app. We support a codebase that was ported from an old PHP app, and it looks like there’s still quite a bit of cruft left that didn’t get YAGNI’ed out during the conversion.
Yet again, the time box caught up with me. I’ve got a few good leads written down to look at later - hopefully we can cut some more out soon!
I was super busy today but luckily was able to work this into another PR I was working on. Redid our main layout to use flexbox, which subsequently allowed to remove a ton of html and css. also killed off a class that was no longer being used just to get some JS in there too.
Writing this response got me going though and I just removed an additional 300 lines of unused library code and a bit of our own code.
Wanted to leave this here – https://kevinjalbert.com/find-and-bury-dead-code/. I had written about how to find and remove dead code, mostly from a Ruby language perspective. It mentions a couple of tools.
I had the same thing happen to me - not sure what to do next.
Looks like the fix is to add the tags file to your .gitignore. Once I did that it seems to run properly. Thanks for the tip @pedrogaspar
I couldn’t get unused to work well enough in the time boxing, but an old method I found earlier in the challenge literally had code after a unconditional return, which I was planning to get to (yesterday, as of this post). So, only a hundred lines or so, but still something.
Thanks for taking the time to come back and update, this worked, thanks!
I ended up finding an unused helper method in one of the specs, and it was an enlightening exercise.
There’s some other code that I know we don’t actually want anymore, but it’ll be a fair amount of work to pull it out, so I’m putting that on the backlog.