Re: What Refactorings Would you Like for C



In article <1d140$47ebf973$5350c6a6$7589@xxxxxxxxxxxxxxxxxxxxxxx>,
moi <root@xxxxxxxxxxxxxxxxxxx> wrote:

I sometimes put all the global variables of a .c file (and the .h file,
of course) into a
(useless) struct. Just to force me to track all the places where it is
referenced.

It's not useless; it makes it visually obvious that the variable you're
accessing is global at the point of use (especially if you name the
struct object something like 'globals'), which both reminds you to be
careful with it and makes it obvious that you won't find the
declaration at the top of the function with the local declarations, and
makes it easy to grep for "anything that touches global state".

As long as you don't delude yourself into thinking it means you only
have one global variable, it's easily worth the extra typing to do it
that way.


dave

--
Dave Vandervies dj3vande at eskimo dot com
[A]ll we really have is a way to measure humans' ability to pass IQ tests.
If we were to write such a test for a cow, it would probably fail the test
(or eat it). --Richard Heathfield in comp.programming
.



Relevant Pages