Identify and eliminate dead code (100+ lines)BRL-CAD
Status: ClosedTime to complete: 72 hrs Mentors: Kesha ShahTags: C, programming, refactoring, reduction, dead code

BRL-CAD is huge.  With any large body of code, one inevitably ends up with a mix of good and bad coding practices.  On the whole, BRL-CAD is actually better than most but we are constantly working on improving the code.  This includes eliminating DEAD code, i.e., code that is not called or used by anything.

References:

  • http://en.wikipedia.org/wiki/Dead_code
  • http://brlcad.org/wiki/Code_Cleanup
  • http://brlcad.org/wiki/Compiling
  • http://brlcad.org/wiki/SVN

This task involves reducing BRL-CAD's source code by 100 or more lines of code by eliminating DEAD code.  You can use whatever method you like to identify dead code, but beware that there are more than 1 million lines of code in BRL-CAD, so you're not likely going to find this duplication just by browsing.  You also cannot eliminate "unused" functions that are declared in our public API headers (i.e., our include/ headers). 

We suggest using a dead code detection tool, but beware false-positives.  You can eliminate a single chunk of dead code or (more likely) several smaller sections of dead code to get to 100+ lines.

One manual way to find dead code is to convert non-library functions (i.e., functions not in the src/lib* directories and not declared in an include/ header) to static functions.  If declared static and not used anywhere, GCC will report it as an unused function during compilation (or throw an error if you're wrong).

Another way to find dead code is through scripting.  You can write a script to extract a list of all function definitions, then search for any that have no uses (in any directory).   A little more tricky to script it right, but you could easily find thousands of lines this way.  We'll create a follow-on task for you to submit your script if you write one this way.

Download our latest Subversion trunk sources and make sure you can compile cleanly first.  Then you can do whatever you need to find dead code.  Make your edits, then make sure the code still compiles (run "make", "make test", "make regress" and "make benchmark" to test your changes)!  This is critical, it must still compile exactly as before.  Finally, create and submit a patch file of your changes (see the references, svn will create the patch file for you).

Feel free to join the brlcad-devel mailing list or IRC channel to discuss your changes beforehand.

Uploaded Work
File name/URLFile sizeDate submitted
BRLCAD.patch16.0 KBDecember 25 2013 21:13 UTC
BRLCAD.patch11.5 KBDecember 26 2013 21:39 UTC
Comments
Станислав Береговon December 23 2013 08:33 UTCTask Claimed

I would like to work on this task.

Kesha Shah on December 23 2013 08:37 UTCTask Assigned

This task has been assigned to Станислав Берегов. You have 72 hours to complete this task, good luck!

Станислав Береговon December 25 2013 21:35 UTCEliminate dead code

I was unable to find any suitable tool for that purpose, so I decided to write something mine and ended up with 120 lines of C++ code, which worked great for me. Maybe now the patch is a mess, but that is because of all the code analysis programs /including the one embedded in Visual Studio/, and I can fix it if needed.

Станислав Береговon December 25 2013 21:35 UTCReady for review

The work on this task is ready to be reviewed.

Sean on December 26 2013 04:04 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Sean on December 26 2013 04:09 UTCquick review

At quick glance, this patch is looking really interesting, but there are a few problems that need to be fixed before the review can proceed.  First, you scanned and modified a few files in our src/other directory.  Noted in a few places, those are not our sources to modify -- they're merely bundled for download convenience.


You can easily exclude them from your patch by running "svn revert src/other".


Also, I noticed that you removed a buf array from src/rt/opt.c which is not an unused variable.  It's just only used in an ifdef block.  You should check all of your modifications to see if there are others that are similarly in a preprocessor block your operating system doesn't get to.


 

Sean on December 26 2013 04:09 UTCDeadline extended

The deadline of the task has been extended with 2 days and 0 hours.

Станислав Береговon December 26 2013 21:40 UTCReady for review

The work on this task is ready to be reviewed.

Sean on December 27 2013 06:46 UTCapplied

Your patch needed modification, but was applied in r59194 -- thank you for your efforts!  You have been credited in our authorship documentation for your efforts.


The one modification that was made was the libbu vfont_free function that you removed.  Publicly declared functions (those declared in the include/ directory) cannot be simply without going through a deprecation process (we don't know if 3rd party source codes call our library).  That said, finding that highlighted a place elsewhere in the code where vfront_free should have been called to release memory, so now it's actually being used.


If your script is able to find any other similar occurrences of unused functions, you can claim as many of these 100+ line reduction tasks as you like.  We'll create more as needed.  If what you wrote is at all portable or if you'd like to make it portable, we could create a task to submit that as well (doesn't matter what language you wrote it in).


Thank you again for your efforts!


 

Sean on December 27 2013 06:47 UTCTask Closed

Congratulations, this task has been completed successfully.