Thread: #ifdef NOT_USED

#ifdef NOT_USED

From
Jaime Casanova
Date:
Hi, i have found several #ifdef NOT_USED marked code... i guess this
is dead code... is safe to remove it? there is some reason you just
hide it and not remove the code?

--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)


Re: #ifdef NOT_USED

From
Bruce Momjian
Date:
Jaime Casanova wrote:
> Hi, i have found several #ifdef NOT_USED marked code... i guess this
> is dead code... is safe to remove it? there is some reason you just
> hide it and not remove the code?

We keep such blocks of code around in case we might need to use it some
day.  It can be removed it the code is useless and will probably never
be used.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 


Re: #ifdef NOT_USED

From
Abhijit Menon-Sen
Date:
(Sorry for the delayed response. I just got home from Germany after my
visit to Linuxtag, and I'm catching up with my -hackers email now.)

At 2005-06-25 09:30:17 -0400, pgman@candle.pha.pa.us wrote:
>
> > Hi, i have found several #ifdef NOT_USED marked code...
>
> We keep such blocks of code around in case we might need to use it
> some day.

I think that's a bad idea. Unused code should be removed with a suitable
CVS checkin comment (and perhaps a comment where the code was), not left
to clutter live code. That's what version control is for.

-- ams


Re: #ifdef NOT_USED

From
Tom Lane
Date:
Abhijit Menon-Sen <ams@oryx.com> writes:
>> We keep such blocks of code around in case we might need to use it
>> some day.

> I think that's a bad idea. Unused code should be removed with a suitable
> CVS checkin comment (and perhaps a comment where the code was),

The code is that comment.  Mostly, these blocks are subroutines that
happen not to be needed right at the moment, but form an obvious part of
a module's API and might be needed again at any time.  (An example is
BufFileTellBlock in buffile.c.)  If someone did need them, they'd be
unlikely to think to root through the CVS history to find if the
functionality they needed had once existed --- they'd probably waste
time rewriting the routine from scratch.

I personally think that the policy of ifdef'ing out API functions just
because they happen to be unreferenced at the moment is a bad idea;
who's to say that someone's extension module won't need the function?
But ifdef is a whole lot better than removing the code completely.

There are other common patterns for NOT_USED --- one is to document
arguments that are passed to, but currently ignored by, functions
following some API or other.

There are a few cases where a NOT_USED block represents functionality
that won't ever be resurrected --- for instance, I just recently removed
the last NOT_USED vestiges of UNDO support in xlog.c, because it's clear
now that we have no intention of going down that design path.  In a
quick look, though, I did not see very many blocks that I'd favor
removing.
        regards, tom lane