GSoC/GCI Archive
Google Code-in 2014 BRL-CAD

Identify and eliminate dead code (100+ lines) #3

completed by: michalp2213

mentors: Deepak, Daniel_R

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.