Re: What Refactorings Would you Like for C
- From: dj3vande@xxxxxxxxxxxxxxxxxxxxxxxxxxx
- Date: Mon, 31 Mar 2008 19:46:07 +0000 (UTC)
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
.
- References:
- What Refactorings Would you Like for C
- From: pingu219
- Re: What Refactorings Would you Like for C
- From: Ian Collins
- Re: What Refactorings Would you Like for C
- From: moi
- What Refactorings Would you Like for C
- Prev by Date: Re: How to find closest point(s) around a specific point in point cloud?
- Next by Date: Re: How to find closest point(s) around a specific point in point cloud?
- Previous by thread: Re: What Refactorings Would you Like for C
- Next by thread: Re: What Refactorings Would you Like for C
- Index(es):
Relevant Pages
|