Identify and eliminate dead code (100+ lines) #2BRL-CAD
Status: ClosedTime to complete: 72 hrs Mentors: Mandeep KaurTags: 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
dead_code_1.diff5.2 KBDecember 19 2013 16:57 UTC
Comments
Peter Amidonon December 19 2013 04:28 UTCTask Claimed

I would like to work on this task.

Mandeep Kaur on December 19 2013 07:34 UTCTask Assigned

This task has been assigned to Andromeda Galaxy. You have 72 hours to complete this task, good luck!

Peter Amidonon December 19 2013 16:57 UTCReady for review

The work on this task is ready to be reviewed.

Sean on December 19 2013 19:36 UTClooks good

Looks good, go ahead and commit if you haven't already.  Note that now you have commit access, you can just apply the patch and let us know the revision numbers in a comment (in addition to posting the patch here so others can see it).  Make your commit message refer to the GCI URL so they bidirectionally reference each other too. 

Sean on December 19 2013 19:37 UTCTask Closed

Congratulations, this task has been completed successfully.

Peter Amidonon December 19 2013 19:56 UTCRevision number

This was committed r59055