Re: Coding style question

From: <korryd(at)enterprisedb(dot)com>
To: "Neil Conway" <neilc(at)samurai(dot)com>
Cc: "imad" <immaad(at)gmail(dot)com>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Coding style question
Date: 2006-11-02 19:23:18
Message-ID: 1162495398.7998.298.camel@sakai.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> > Shouldn't we turn on warnings by the compiler on uninitialized
> > variables? This can also be helpful.
>
> Those warnings should already be enabled, at least with GCC.

Yes, the compiler can detect unitialized variables,

But, that introduces a new problem. There are a lot of tools out there
(like GCC) that can find unitialized variables (or more specifically,
variables which are used before initialization). I've seen too many
less-scarred developers add an " = NULL" to quiet down the tool. But
that's (arguably) worse than leaving the variable uninitialized - if you
simply initialize a variable to a known (but not correct) value, you've
disabled the tool; it can't help you find improperly initialized
variables anymore. The variable has a value, but you still don't know
at which point in time it has a correct value.

That's another reason I prefer initializers (and nested variable
declarations) - I can put off creating the variable until I can assign a
meaningful value to it. (I don't go so far as to introduce artificial
scopes just for the sake of nesting variable declarations).

Too many scars...

-- Korry

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2006-11-02 19:40:14 Re: Coding style question
Previous Message Tom Lane 2006-11-02 19:23:05 Re: Coding style question