Re: A small rant about coding style for backend functions

From: "Brendan Jurd" <direvus(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: A small rant about coding style for backend functions
Date: 2007-08-18 01:57:53
Message-ID: 37ed240d0708171857t28e77509j482e021029ea2cbf@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 8/18/07, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> The main drawback to the V1-call-convention function call mechanism,
> compared to ordinary C functions, is that you can't instantly see what
> the function arguments are supposed to be. I think that good coding
> style demands ameliorating this by declaring and extracting all the
> arguments at the top of the function. The above example is bad enough,
> but when you have to dig through a function of many lines looking for
> GETARG calls in order to know what arguments it expects, it's seriously
> annoying and unreadable.
>
> And another thing: use the correct extraction macro for the argument's
> type, rather than making something up on the fly. Quite aside from
> helping the reader see what the function expects, the first example
> above is actually *wrong*, as it will crash on toasted input.

This is all useful guidance. My question is why it's not part of the
developer documentation. Which brings me around to a minor rant of my
own.

All the developer FAQ has to say about coding style is that we use
4-space tabs for indentation, and that you should "merge seamlessly
into the surrounding code". That isn't much solace when the
surrounding code is itself nigh unreadable or doesn't contain examples
of what you are trying to do.

For postgres hacking newbies (such as myself), the lack of any obvious
published coding standards for the project is daunting, and is bound
to lead to those developers "filling in the blanks" with their own
coding style biases. Which means the patch reviewers need to spend
time pointing out the flaws, and the submitter needs to spend time
adjusting, testing and resubmitting ... it's all quite avoidable.

I humbly suggest that if the sort of valuable information posted by
Tom here was documented instead of ranted to the mailing list, maybe
you guys wouldn't have to do so much ranting =)

Cheers
BJ

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message tomas 2007-08-18 04:03:15 Re: tsearch2 in PostgreSQL 8.3?
Previous Message Josh Berkus 2007-08-17 23:40:43 Re: tsearch2 in PostgreSQL 8.3?