Re: [HACKERS] Coding style question

2006-11-03 Thread Andrew Dunstan
Nolan Cafferky wrote: This may not inform the current conversation at all, but a while back I went on a cross-compiler compatibility binge for all of my active projects, and I found that some compilers (*cough* Borland *cough) had some very strange compiler/run time errors unless all variable

Re: [HACKERS] Coding style question

2006-11-03 Thread Nolan Cafferky
I think Tom stated it pretty well: When the variable is going to be set anyway in straight-line code at the top of the function, then it's mostly a matter of taste whether you set it with an initializer or an assignment. the key phrase is: "set anyway in straigh-tline code at the top of

Re: [HACKERS] Coding style question

2006-11-02 Thread korryd
Well, clearly you should only assign meaningful values to variables, but I don't see anything wrong with omitting an initializer, initializing the variable before using it, and letting the compiler warn you if you forget to do this correctly. The problem that that introduces is that you

Re: [HACKERS] Coding style question

2006-11-02 Thread korryd
<[EMAIL PROTECTED]> writes: > initializers also force you to declare variables in the scope where they > are needed. Instead of declaring every variable at the start of the > function, it's better to declare them as nested as practical (not as > nested as possible, but as nested as practical

Re: [HACKERS] Coding style question

2006-11-02 Thread Neil Conway
On Thu, 2006-11-02 at 14:23 -0500, [EMAIL PROTECTED] wrote: > Yes, the compiler can detect unitialized variables, In most situations, anyway. > 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 > uninitia

Re: [HACKERS] Coding style question

2006-11-02 Thread imad
On 11/3/06, Tom Lane <[EMAIL PROTECTED]> wrote: imad <[EMAIL PROTECTED]> writes: > Well, its about the coding style. And I doubt there exists a data type > which may not have > an initializer. A NULL / Zero is an option in all cases and you can do > whatever you want to assign it a value immediat

Re: [HACKERS] Coding style question

2006-11-02 Thread Tom Lane
<[EMAIL PROTECTED]> writes: > initializers also force you to declare variables in the scope where they > are needed. Instead of declaring every variable at the start of the > function, it's better to declare them as nested as practical (not as > nested as possible, but as nested as practical). I

Re: [HACKERS] Coding style question

2006-11-02 Thread korryd
Yeah, I agree with that. But as Andrew noted, we don't really have any hard and fast coding rules --- the only guideline is to do your best to make your code readable, because other people *will* have to read it. I'm not really looking for hard/fast rules.  Just picking brains.  In t

Re: [HACKERS] Coding style question

2006-11-02 Thread Tom Lane
imad <[EMAIL PROTECTED]> writes: > Well, its about the coding style. And I doubt there exists a data type > which may not have > an initializer. A NULL / Zero is an option in all cases and you can do > whatever you want to assign it a value immediately after the > initialization section. My two cen

Re: [HACKERS] Coding style question

2006-11-02 Thread korryd
> 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 the

Re: [HACKERS] Coding style question

2006-11-02 Thread korryd
The disadvantage of using initializers is that you end up contorting the code to allow you to squeeze things into the initializers and it limits what you can do later to the code without undoing them. For example, if later you find out you have to, say, lock a table before the itupdesc init

Re: [HACKERS] Coding style question

2006-11-02 Thread Tom Lane
Gregory Stark <[EMAIL PROTECTED]> writes: > People expect initializers to be simple expressions, macro calls, accessor > functions, and so on. Not to call out to complex functions that implement key > bits of the function behaviour. Yeah, I agree with that. But as Andrew noted, we don't really ha

Re: [HACKERS] Coding style question

2006-11-02 Thread imad
On 11/2/06, Gregory Stark <[EMAIL PROTECTED]> wrote: <[EMAIL PROTECTED]> writes: > I would probably write that as: > > > > static TransactionId > _bt_check_unique(Relation rel, IndexTuple itup, Relation heapRel, >

Re: [HACKERS] Coding style question

2006-11-02 Thread Andrew Dunstan
Gregory Stark wrote: <[EMAIL PROTECTED]> writes: I would probably write that as: static TransactionId _bt_check_unique(Relation rel, IndexTuple itup, Relation heapRel, Buffer buf, ScanKey itup_scankey

Re: [HACKERS] Coding style question

2006-11-02 Thread Neil Conway
On Thu, 2006-11-02 at 23:53 +0500, imad wrote: > 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. -Neil ---(end of broadcast)--- TIP

Re: [HACKERS] Coding style question

2006-11-02 Thread Gregory Stark
<[EMAIL PROTECTED]> writes: > I would probably write that as: > > > > static TransactionId > _bt_check_unique(Relation rel, IndexTuple itup, Relation heapRel, > Buffer buf, ScanKey itup_scankey) > { > Tup

Re: [HACKERS] Coding style question

2006-11-02 Thread imad
Shouldn't we turn on warnings by the compiler on uninitialized variables? This can also be helpful. --Imad www.EnterpriseDB.com On 11/2/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: I've noticed a trend in the PostgreSQL code base - for some reason, we tend to avoid initializing automatic

[HACKERS] Coding style question

2006-11-02 Thread korryd
I've noticed a trend in the PostgreSQL code base - for some reason, we tend to avoid initializing automatic variables (actually, the code base is pretty mixed on this point). For example in _bt_check_unique() we have: static TransactionId _bt_check_unique(Relation rel, IndexTuple itup, Rel