Thread: driver source code indentation

driver source code indentation

From
Liam Stewart
Date:
I suggest that the JDBC driver adopt PostgreSQL's indentation standards
(see PostgreSQL developers FAQ, question 1). I see that some source
files have used this standard, but the vast majority do not. We should
have a standard for consistency and our own sanity if nothing else.

Liam

--
Liam Stewart :: Red Hat Canada, Ltd. :: liams@redhat.com

Re: driver source code indentation

From
Bruce Momjian
Date:
>
> I suggest that the JDBC driver adopt PostgreSQL's indentation standards
> (see PostgreSQL developers FAQ, question 1). I see that some source
> files have used this standard, but the vast majority do not. We should
> have a standard for consistency and our own sanity if nothing else.

Glad someone brought this up.  A while ago I wrote:

    I tried pgindent but it doesn't understand Java and made a mess of it.
    I used astyle with the options:

            $ astyle --style=java -j *.java

    I have the reformatted jdbc files at:

            ftp://candle.pha.pa.us/pub/postgresql/astyle_jdbc.tar.gz

    I must say it looks very good.

Can people tak a look at that and see if they like it?  I will work on
astyle to find a format that matches the main code indenting.

If you like it, I will indent just after we go beta.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Re: driver source code indentation

From
Barry Lind
Date:
I agree that this is needed.  In fact I know Bruce wants to do something
in this area.  In fact he sent out a few months ago a sample of the code
after it had been cleaned up by some tool.  At the time no one seemed to
be very interested.  Going forward for 7.2 I think now is the time that
something should be done.  We need the equivalent of pgindent for java.

I am OK with the style used for the C code.  However I would like the
following additional step done for the java code:  replace all tabs with
spaces.

I often end up viewing files in editors/viewers other than the one I
normally code with.  Having to worry about getting the tab settings
correct so that the code is readable is a pain (and sometimes not
possible depending on the editor).  I have personally adopted in my java
IDE of choice (JBuilder) to have the IDE automatically replace tabs with
spaces for this reason.

thanks,
--Barry


Liam Stewart wrote:
> I suggest that the JDBC driver adopt PostgreSQL's indentation standards
> (see PostgreSQL developers FAQ, question 1). I see that some source
> files have used this standard, but the vast majority do not. We should
> have a standard for consistency and our own sanity if nothing else.
>
> Liam
>
>



Re: driver source code indentation

From
Liam Stewart
Date:
On Tue, Sep 04, 2001 at 03:25:33PM -0400, Bruce Momjian wrote:
>     I must say it looks very good.
>
> Can people tak a look at that and see if they like it?  I will work on
> astyle to find a format that matches the main code indenting.

I like it. The following results in a closer match to the main
PostgreSQL code:

$ astyle --style=java -b -p -j foo.java

I'm in agreement with Barry about using spaces instead of tabs. astyle
does that by default (at least with the java style).

> If you like it, I will indent just after we go beta.

Yes, please.

Liam

--
Liam Stewart :: Red Hat Canada, Ltd. :: liams@redhat.com

Re: driver source code indentation

From
"Ross J. Reedstrom"
Date:
On Tue, Sep 04, 2001 at 12:43:21PM -0700, Barry Lind wrote:
<snip>

> I am OK with the style used for the C code.  However I would like the
> following additional step done for the java code:  replace all tabs with
> spaces.


Oh noooooo! Barry's stumbled over the tripwire of the Tab/Spaces flamewar trap!
Everyone duck!

More seriously, this was actually voted on some time ago. (Check the HACKERS
archives) Since the JDBC source is well segregated from the rest of the
tree, it can have a different style, but if you want to adopt the 'standard'
style, I'd suggest going all the way.

In the other hand, since you'll need to use a different tool to maintain the
style (unless Bruce update his pgident to handle java ...) it'll never be
completely the same, anyway. I'd image that the core developers will go with
whatever the JDBC maintainers want.


Ross

Re: driver source code indentation

From
Tom Lane
Date:
Barry Lind <barry@xythos.com> writes:
> I am OK with the style used for the C code.  However I would like the
> following additional step done for the java code:  replace all tabs with
> spaces.

I disagree with this, because then we are *not* applying the same coding
standards in the backend and in JDBC.  If you want to propose that we
dispense with tabs throughout the system, feel free to propose that ---
but it was shot down last time and likely will be again.

I personally concur that four-space tabs is a horrible standard, and
would much rather see us using eight-space tab stops.  But I haven't
been able to obtain any significant consensus for that view.  Some
developers apparently use editors where a physical tab character needs
to equal the logical indent amount...

            regards, tom lane

Re: driver source code indentation

From
Anders Bengtsson
Date:
On Tue, 4 Sep 2001, Bruce Momjian wrote:

> Can people tak a look at that and see if they like it?  I will work on
> astyle to find a format that matches the main code indenting.
>
> If you like it, I will indent just after we go beta.

Looks great!

I only noticed two things that I sort of disliked. Luckily this seems to
be the only differences between the example and the standard used in the C
sources! :) It's also the only differences between the example and Sun's
standard that I could see.

* Missing a space between "if" and "(".
* Missing a space after a type cast.

/Anders
_____________________________________________________________________
A n d e r s  B e n g t s s o n                   ndrsbngtssn@yahoo.se
Stockholm, Sweden


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


Re: driver source code indentation

From
"Thomas O'Dowd"
Date:
On Tue, Sep 04, 2001 at 04:59:20PM -0400, Tom Lane wrote:
> Barry Lind <barry@xythos.com> writes:
> > I am OK with the style used for the C code.  However I would like the
> > following additional step done for the java code:  replace all tabs with
> > spaces.
>
> I disagree with this, because then we are *not* applying the same coding
> standards in the backend and in JDBC.  If you want to propose that we
> dispense with tabs throughout the system, feel free to propose that ---
> but it was shot down last time and likely will be again.
>
> I personally concur that four-space tabs is a horrible standard, and
> would much rather see us using eight-space tab stops.  But I haven't
> been able to obtain any significant consensus for that view.  Some
> developers apparently use editors where a physical tab character needs
> to equal the logical indent amount...

I'm putting in my vote for keeping tabs and not using spaces. The thing
I love about tabs is the ability to change the tabstop according to your
needs. It's a flexibility that you don't get with spaces. Then again
I do all my coding in vim. Other than that I'm all for cleaning up the
source code to the one standard. Go for it!

Tom.
--
Thomas O'Dowd. - Nooping - http://nooper.com
tom@nooper.com - Testing - http://nooper.co.jp/labs

Re: driver source code indentation

From
Dave Cramer
Date:
Well, my vote would be for a 2 space indent.

Dave
On Tue, 2001-09-04 at 16:59, Tom Lane wrote:
> Barry Lind <barry@xythos.com> writes:
> > I am OK with the style used for the C code.  However I would like the
> > following additional step done for the java code:  replace all tabs with
> > spaces.
>
> I disagree with this, because then we are *not* applying the same coding
> standards in the backend and in JDBC.  If you want to propose that we
> dispense with tabs throughout the system, feel free to propose that ---
> but it was shot down last time and likely will be again.
>
> I personally concur that four-space tabs is a horrible standard, and
> would much rather see us using eight-space tab stops.  But I haven't
> been able to obtain any significant consensus for that view.  Some
> developers apparently use editors where a physical tab character needs
> to equal the logical indent amount...
>
>             regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>
>




Re: driver source code indentation

From
"Dave Cramer"
Date:
This does look good,

I personally prefer more whitespace

After ( and , as well as moving the opening brace to the next line.

Public int foo(int x,int y){
    x=y;
}

Turns into

Public int foo( int x, int y )
{
    x = y;
}


I find this easier to read.

Comments?

Dave


-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org
[mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Bruce Momjian
Sent: September 4, 2001 3:26 PM
To: Liam Stewart
Cc: pgsql-jdbc@postgresql.org
Subject: Re: [JDBC] driver source code indentation


>
> I suggest that the JDBC driver adopt PostgreSQL's indentation
> standards
> (see PostgreSQL developers FAQ, question 1). I see that some source
> files have used this standard, but the vast majority do not. We should
> have a standard for consistency and our own sanity if nothing else.

Glad someone brought this up.  A while ago I wrote:

    I tried pgindent but it doesn't understand Java and made a mess
of it.
    I used astyle with the options:

            $ astyle --style=java -j *.java

    I have the reformatted jdbc files at:

            ftp://candle.pha.pa.us/pub/postgresql/astyle_jdbc.tar.gz

    I must say it looks very good.

Can people tak a look at that and see if they like it?  I will work on
astyle to find a format that matches the main code indenting.

If you like it, I will indent just after we go beta.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania
19026

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly



Re: driver source code indentation

From
Bruce Momjian
Date:
> On Tue, 4 Sep 2001 15:25:33 -0400 (EDT), you wrote:
> >    I have the reformatted jdbc files at:
> >            ftp://candle.pha.pa.us/pub/postgresql/astyle_jdbc.tar.gz
> >Can people tak a look at that and see if they like it?
>
> The developer's FAQ says "Our standard format is to indent each
> code level with one tab, where each tab is four spaces", but in
> the reformatted files I don't see any tabs. It indents
> everything with spaces. Is that intentional?

Should have tabs.  Let me work on a new version.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Re: driver source code indentation

From
Rene Pijlman
Date:
On Thu, 6 Sep 2001 07:06:29 -0400, you wrote:
>Public int foo(int x,int y){
>    x=y;
>}
>
>Turns into
>
>Public int foo( int x, int y )
>{
>    x = y;
>}
>
>
>I find this easier to read.

I agree. This is my preference as well in Java.

Regards,
René Pijlman <rene@lab.applinet.nl>

Re: driver source code indentation

From
Rene Pijlman
Date:
On Tue, 4 Sep 2001 15:25:33 -0400 (EDT), you wrote:
>    I have the reformatted jdbc files at:
>            ftp://candle.pha.pa.us/pub/postgresql/astyle_jdbc.tar.gz
>Can people tak a look at that and see if they like it?

The developer's FAQ says "Our standard format is to indent each
code level with one tab, where each tab is four spaces", but in
the reformatted files I don't see any tabs. It indents
everything with spaces. Is that intentional?

Regards,
René Pijlman <rene@lab.applinet.nl>

Re: driver source code indentation

From
Barry Lind
Date:
Dave,

I agree with you, and it seems that much of the existing jdbc code is
formated that way.  But before starting a thread on what everybody
prefers as their java format, let me first ask the question:


Should the jdbc java code use the same formatting as the C code?

If the answer is yes, then we know what the format is going to be.  Else
we can have what I am sure will be a long religious battle on what style
would be best for the java code.

My personal vote is to stick with the same format as the C code.  While
personally I think a different format would be better, I don't think it
is worth the hassle, and I can live with the existing format.

thanks,
--Barry



Dave Cramer wrote:
> Well, my vote would be for a 2 space indent.
>
> Dave
> On Tue, 2001-09-04 at 16:59, Tom Lane wrote:
>
>>Barry Lind <barry@xythos.com> writes:
>>
>>>I am OK with the style used for the C code.  However I would like the
>>>following additional step done for the java code:  replace all tabs with
>>>spaces.
>>>
>>I disagree with this, because then we are *not* applying the same coding
>>standards in the backend and in JDBC.  If you want to propose that we
>>dispense with tabs throughout the system, feel free to propose that ---
>>but it was shot down last time and likely will be again.
>>
>>I personally concur that four-space tabs is a horrible standard, and
>>would much rather see us using eight-space tab stops.  But I haven't
>>been able to obtain any significant consensus for that view.  Some
>>developers apparently use editors where a physical tab character needs
>>to equal the logical indent amount...
>>
>>            regards, tom lane
>>
>>---------------------------(end of broadcast)---------------------------
>>TIP 5: Have you checked our extensive FAQ?
>>
>>http://www.postgresql.org/users-lounge/docs/faq.html
>>
>>
>>
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>
>



Re: driver source code indentation

From
Bruce Momjian
Date:
> Dave,
>
> I agree with you, and it seems that much of the existing jdbc code is
> formated that way.  But before starting a thread on what everybody
> prefers as their java format, let me first ask the question:
>
>
> Should the jdbc java code use the same formatting as the C code?
>
> If the answer is yes, then we know what the format is going to be.  Else
> we can have what I am sure will be a long religious battle on what style
> would be best for the java code.
>
> My personal vote is to stick with the same format as the C code.  While
> personally I think a different format would be better, I don't think it
> is worth the hassle, and I can live with the existing format.
>

Agreed.  That is the direction I am heading.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Re: driver source code indentation

From
Liam Stewart
Date:
On Thu, Sep 06, 2001 at 09:51:19AM -0700, Barry Lind wrote:

> Should the jdbc java code use the same formatting as the C code?

IMHO, yes: for consistency and because it is, at the moment, part of the
main "package".

Liam

--
Liam Stewart :: Red Hat Canada, Ltd. :: liams@redhat.com

Re: driver source code indentation

From
Bruce Momjian
Date:
>
> On Tue, Sep 04, 2001 at 03:25:33PM -0400, Bruce Momjian wrote:
> >     I must say it looks very good.
> >
> > Can people tak a look at that and see if they like it?  I will work on
> > astyle to find a format that matches the main code indenting.
>
> I like it. The following results in a closer match to the main
> PostgreSQL code:
>
> $ astyle --style=java -b -p -j foo.java
>
> I'm in agreement with Barry about using spaces instead of tabs. astyle
> does that by default (at least with the java style).

OK, I have created pgjindent in src/tools/pgindent, and ran it over the
current CVS.  It compiles so it should be fine:

    ftp://candle.pha.pa.us/pub/postgresql/astyle_jdbc.tar.gz

I am using the same formatting as the PostgreSQL C code, including tab
size.

I will run this before beta. I will also fix the "if(" to "if (".  Any
other issues, please let me know.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Re: driver source code indentation

From
Rene Pijlman
Date:
On Fri, 7 Sep 2001 17:25:19 -0400 (EDT), you wrote:
>OK, I have created pgjindent in src/tools/pgindent, and ran it over the
>current CVS.  It compiles so it should be fine:
>
>    ftp://candle.pha.pa.us/pub/postgresql/astyle_jdbc.tar.gz

This looks good.

Regards,
René Pijlman <rene@lab.applinet.nl>