From: Gavin Flower <GavinFlower@archidevsys.co.nz>
To: Dave Cramer <pg@fastcrypt.com>
Cc: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
Cc: Markus KARG <markus@headcrashing.eu>
Cc: List <pgsql-jdbc@postgresql.org>
Subject: Re: PgJDBC: code reformat
Date: Tue, 29 Dec 2015 10:16:28 +1300
Message-ID: <5681A6AC.3040308@archidevsys.co.nz> (raw)
In-Reply-To: <CADK3HHJkFMo1eYujhnDtzH9z8K2Bh+3BPLx4+9p_U_=4x+6w6w@mail.gmail.com>
References: <CAB=Je-F1PtJ1Dbsswr=oaj2z8KYpZANHW_kLc2y5DuzjpAJqeQ@mail.gmail.com>
<062c01d14031$c4f01aa0$4ed04fe0$@eu>
<CAB=Je-GTY_09RLYOA9FgoydadEyiGD+ea+xvDqt7J0ijYnqPfg@mail.gmail.com>
<CADK3HHLGRSzbWnbkwixGz2dregiBJJMSBtA9NaUt3eYC8RZ+cA@mail.gmail.com>
<567FEF32.9010300@archidevsys.co.nz>
<CADK3HHLD3aAWcEPtUXVCxDrLzENvpAGbqC__dYfzrKEz1wh2VA@mail.gmail.com>
<567FF2A3.8060003@archidevsys.co.nz>
<CAB=Je-He4RtXP-m2vkD9KKm+vPwFY7y3M-z_cKtmho=tExiJmg@mail.gmail.com>
<56805192.4040901@archidevsys.co.nz>
<CADK3HHJkFMo1eYujhnDtzH9z8K2Bh+3BPLx4+9p_U_=4x+6w6w@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>
On 29/12/15 01:22, Dave Cramer wrote:
>
> On 28/12/15 04:01, Vladimir Sitnikov wrote:
>
[...]
>
>
> Compare this one:
> https://github.com/pgjdbc/pgjdbc/blob/197175039068446a15c30d2b5e949f1eae08515d/pgjdbc/src/main/java/...
> with this one:
> https://github.com/pgjdbc/pgjdbc/blob/197175039068446a15c30d2b5e949f1eae08515d/pgjdbc/src/main/java/...
>
> Do you see how QueryExecutorImpl.java#L264-L311 is much readable?
>
> No. Possibly I'm not seeing the code you want me too?
>
> Same problem here, one of them shows comments. I believe the first one.
Comments can be good, but are orthogonal to the question of code style.
>
> I would add more blank lines for readability, but would eliminate
> blank lines after opening brackets and before closing brackets.
>
> Also would simplify lines to ease readability and improve ability
> to debug, eg
>
>
> So there are very good reasons in Java not to do what you are
> proposing below. Mostly because it creates objects which have to be
> garbage collected.
Hmm...
I suspected that the Just-in-Time compiler (I knew from my previous
research that they are truly vicious when it comes to optimisation!!!)
would end with up with the same code, and actually ran a test that
proved it.
I ran multiple loops with and without an intermediate variable, the
variation between runs of the same type was vastly greater than the
difference in the means - each run was about 34 seconds.
I looked at the output of -XX:CompileCommand=print and found that the
optimised code was identical, even though the initial byte code was
different!
In essence, adding an intermediate variable makes no difference in the
long run.
So making code more readable does NOT lead to any noticeable reduction
in performance when the coded is executed many times. I strongly
suspect that the difference in code executed just once in a run, would
be insignificant compared to the noise in measuring the run times in
practice.
Therefore, since programmer time is costly, it make more sense to put
effort into code readability, than into premature micro optimisations.
Which is basically what most texts books on optimisation say.
If you want, I can send you the gory details in an OpenDocument file
(e.g. one produced natively by LibreOffice).
> While I agree that it is more readable. I think driver code has a
> responsibility to be as curt as possible with respect to creating objects.
In practice, the changes I have suggested do not have that problem.
> Would rewrite:
> ((V3ParameterList) parameterList).checkAllParametersSet();
> as
> V3ParameterList v3ParameterList =(V3ParameterList) parameterList;
> v3ParameterList.checkAllParametersSet();
>
>
> and would rewrite:
> if ((flags &QueryExecutor.QUERY_SUPPRESS_BEGIN)
> !=0||protoConnection.getTransactionState()
> !=ProtocolConnection.TRANSACTION_IDLE)
> as
> boolean abc =(flags &QueryExecutor.QUERY_SUPPRESS_BEGIN) !=0;
> boolean xyz = protoConnection.getTransactionState()
> !=ProtocolConnection.TRANSACTION_IDLE;
> if (abc||xyz)
> (except I would use more meaningful names for 'abc' & 'xyz' above!)
>
> I also only ever have one return per method, as that makes it
> easier to:
> (1) understand
> (2) maintain (add new code and/or change existing code)
> (3) debug
>
>
> PgResultSet#getFastLong is very hard to follow no matter which
> way you
> format the braces.
> I believe, "readability" comes from proper segmentation (code
> blocks
> vs methods) and proper variable naming.
>
>
>
>
> Dave Cramer
>
> davec@postgresintl.com <mailto:davec@postgresintl.com>
> www.postgresintl.com <http://www.postgresintl.com/;
>
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: GavinFlower@archidevsys.co.nz, pg@fastcrypt.com, sitnikov.vladimir@gmail.com, markus@headcrashing.eu
Subject: Re: PgJDBC: code reformat
In-Reply-To: <5681A6AC.3040308@archidevsys.co.nz>
References: <CAB=Je-F1PtJ1Dbsswr=oaj2z8KYpZANHW_kLc2y5DuzjpAJqeQ@mail.gmail.com> <062c01d14031$c4f01aa0$4ed04fe0$@eu> <CAB=Je-GTY_09RLYOA9FgoydadEyiGD+ea+xvDqt7J0ijYnqPfg@mail.gmail.com> <CADK3HHLGRSzbWnbkwixGz2dregiBJJMSBtA9NaUt3eYC8RZ+cA@mail.gmail.com> <567FEF32.9010300@archidevsys.co.nz> <CADK3HHLD3aAWcEPtUXVCxDrLzENvpAGbqC__dYfzrKEz1wh2VA@mail.gmail.com> <567FF2A3.8060003@archidevsys.co.nz> <CAB=Je-He4RtXP-m2vkD9KKm+vPwFY7y3M-z_cKtmho=tExiJmg@mail.gmail.com> <56805192.4040901@archidevsys.co.nz> <CADK3HHJkFMo1eYujhnDtzH9z8K2Bh+3BPLx4+9p_U_=4x+6w6w@mail.gmail.com> <5681A6AC.3040308@archidevsys.co.nz>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox