I'm fairly displeased with what pgindent has done to single-line PG_TRY
constructs, as in this example from pl_exec.c:

*************** exec_stmt_block(PLpgSQL_execstate * esta
*** 911,922 ****
                                 SPI_result_code_string(xrc));
  
                PG_TRY();
!               {
!                       rc = exec_stmts(estate, block->body);
!               }
                PG_CATCH();
                {
!                       ErrorData *edata;
                        PLpgSQL_exceptions *exceptions;
                        int                     j;
  
--- 912,921 ----
                                 SPI_result_code_string(xrc));
  
                PG_TRY();
!               rc = exec_stmts(estate, block->body);
                PG_CATCH();
                {
!                       ErrorData  *edata;
                        PLpgSQL_exceptions *exceptions;
                        int                     j;
  
*************** exec_stmt_block(PLpgSQL_execstate * esta

On the whole I'd prefer that pgindent not suppress "unnecessary"
brace pairs at all.

			regards, tom lane

Sun, 12 Sep 2004 13:40:02 -0400
Tom Lane <tgl@sss.pgh.pa.us>
pgindent vs try/catch
Tom Lane said:
> I'm fairly displeased with what pgindent has done to single-line PG_TRY
> constructs, as in this example from pl_exec.c:
>
> *************** exec_stmt_block(PLpgSQL_execstate * esta
> *** 911,922 ****
>                                 SPI_result_code_string(xrc));
>
>                PG_TRY();
> !               {
> !                       rc = exec_stmts(estate, block->body);
> !               }
>                PG_CATCH();
>                {
> !                       ErrorData *edata;
>                        PLpgSQL_exceptions *exceptions;
>                        int                     j;
>
> --- 912,921 ----
>                                 SPI_result_code_string(xrc));
>
>                PG_TRY();
> !               rc = exec_stmts(estate, block->body);
>                PG_CATCH();
>                {
> !                       ErrorData  *edata;
>                        PLpgSQL_exceptions *exceptions;
>                        int                     j;
>
> *************** exec_stmt_block(PLpgSQL_execstate * esta
>
> On the whole I'd prefer that pgindent not suppress "unnecessary"
> brace pairs at all.


I had that argument a while ago with Bruce and lost :-) . It does horrible
things to if/else constructs too. The workaround is to put a comment in the
block. On the whole I agree with you, though. If I put braces in my program
it's for a reason, and the indenter shouldn't think it knows better than me.

cheers

andrew



Sun, 12 Sep 2004 13:58:05 -0500 (CDT)
"Andrew Dunstan" <andrew@dunslane.net>
Re: pgindent vs try/catch
Andrew Dunstan wrote:

> Tom Lane said:
> 
>>I'm fairly displeased with what pgindent has done to single-line PG_TRY
>>constructs, as in this example from pl_exec.c:
>>
>>*************** exec_stmt_block(PLpgSQL_execstate * esta
>>*** 911,922 ****
>>                                SPI_result_code_string(xrc));
>>
>>               PG_TRY();
>>!               {
>>!                       rc = exec_stmts(estate, block->body);
>>!               }
>>               PG_CATCH();
>>               {
>>!                       ErrorData *edata;
>>                       PLpgSQL_exceptions *exceptions;
>>                       int                     j;
>>
>>--- 912,921 ----
>>                                SPI_result_code_string(xrc));
>>
>>               PG_TRY();
>>!               rc = exec_stmts(estate, block->body);
>>               PG_CATCH();
>>               {
>>!                       ErrorData  *edata;
>>                       PLpgSQL_exceptions *exceptions;
>>                       int                     j;
>>
>>*************** exec_stmt_block(PLpgSQL_execstate * esta
>>
>>On the whole I'd prefer that pgindent not suppress "unnecessary"
>>brace pairs at all.
> 
> 
> 
> I had that argument a while ago with Bruce and lost :-) . It does horrible
> things to if/else constructs too. The workaround is to put a comment in the
> block. On the whole I agree with you, though. If I put braces in my program
> it's for a reason, and the indenter shouldn't think it knows better than me.

Well I'm not exactly a C coder, I'm a C++ one and it's quite common use the
extra scope in order to reduce the automatic variable life, I don't know how
much the extra scope are used in the C world, however remove an "extra scope"
like that is not only "horrible", is *wrong* and can be cause of future pain:


foo (  int a )
{
   ...
   {
       int a;	
   }
   // use the formal parameter
}

if the extra scope is removed the local variable "shadow" the formal
parameter. Some compilers do not warning you, IIRC the Digital had this funny omission,
( however you can miss the warning ) and hours of debugging are behind the corner.
I hope that Bruce change his mind...


Regards
Gaetano Mendola



















Sun, 12 Sep 2004 21:39:10 +0200
Gaetano Mendola <mendola@bigfoot.com>
Re: pgindent vs try/catch
Andrew Dunstan wrote:
> I had that argument a while ago with Bruce and lost :-) . It does horrible
> things to if/else constructs too. The workaround is to put a comment in the
> block. On the whole I agree with you, though. If I put braces in my program
> it's for a reason, and the indenter shouldn't think it knows better than me.

I have removed the code from pgindent.  Now how do we clean up the
try/catch code that got messed up?

The original purpose of that code was to clean up the code we inherited
from Berkeley that had lots of excessive brace blocks and the pgindent 
code just remained.

-- 
  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, Pennsylvania 19073

Sun, 12 Sep 2004 18:14:15 -0400 (EDT)
Bruce Momjian <pgman@candle.pha.pa.us>
Re: pgindent vs try/catch
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> I have removed the code from pgindent.  Now how do we clean up the
> try/catch code that got messed up?

I've hand-restored the cases that are in the files I'm currently
editing.  I'll look for more later.

			regards, tom lane

Sun, 12 Sep 2004 18:43:59 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: pgindent vs try/catch 