Eliminate any library global variable #4BRL-CAD
Status: ClosedTime to complete: 100 hrs Mentors: Hardeep Singh Rai, IshwerdasTags: C, global, cleanup, code refactoring, reduction

BRL-CAD is a very large mature code base and as with such body of code, issues creep in over time that are undesirable. One such issue is the introduction of global variables. They are often a short-term crutch that allows some feature to be implemented quickly, but they become a long-term burden.

All you need to do is eliminate any one of them that is declared in a header and accessed in more than one file. That means static globals don't count and variables declared global in one file but not used anywhere else also don't count. That said, we try to make it clear where our shared globals are at by putting their definitions in one place (see references below).

You also must preserve the behavior and capabilities of code that was using the global and remove the variable cleanly. That is to say, for example, that if there was a global variable storing a date string that is printed, you can't just eliminate the variable and remove the line that printed the variable -- you'd probably replace the code printing the date with a function or pass the date in from calling code.

This task is to eliminate just ONE global variable in any of our libraries. If you're quick and clever, you'll notice that some globals are VERY simple to eliminate while others can be complicated with thousands of lines of code needing to get updated.

Submit a patch file

References:
  • src/libbu/globals.c
  • src/libbn/globals.c
  • src/librt/globals.c
  • http://brlcad.org/wiki/Patches
Modify:
  • What you'll have to modify completely depends on how you're going to remove the global.
Uploaded Work
File name/URLFile sizeDate submitted
db5_enc_len_removal1.7 KBDecember 07 2014 05:46 UTC
Comments
Marc Tannouson December 7 2014 05:14 UTCTask Claimed

I would like to work on this task.

Gauravjeet Singh on December 7 2014 05:38 UTCTask Assigned

This task has been assigned to Marc Tannous. You have 100 hours to complete this task, good luck!

Marc Tannouson December 7 2014 05:46 UTCReady for review

The work on this task is ready to be reviewed.

Sean on December 7 2014 07:31 UTCTask Closed

Congratulations, this task has been completed successfully.

Sean on December 7 2014 07:35 UTCnot ideal

Duplicating the values in two places is far from ideal, but this does conform with Rule of Three (i.e., duplication exists in fewer than three places).  That said, I closed this slightly too soon.  Notice the declaration in include/db5.h that needed to be removed.  Minor issue, but good point to make sure you search the entire tree (or use a system like ctags/etags).

Marc Tannouson December 7 2014 07:38 UTCHow should I have done it?

I used 'grep -r 'db5_enc_len' ' while on /src/ to search that string recursively in all the files, so that I know where to change it.


If declarating the variable locally was not the way to do it, how should I have approached it?


Regards,


Marc