Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #36723

Re: Style police (Was: Re: How to handle same sanity checks)

From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: Style police (Was: Re: How to handle same sanity checks)
Date 2017-06-25 19:14 -0400
Organization Aioe.org NNTP Server
Message-ID <oipg4v$itb$1@gioia.aioe.org> (permalink)
References <87o9tgo0a9.fsf@munus.decebal.nl> <er9hnkFql1qU1@mid.individual.net> <oiov2l$1nso$1@gioia.aioe.org> <oip9ms$tkh$1@dont-email.me>

Show all headers | View raw


On 6/25/2017 5:28 PM, Eric Sosman wrote:
> On 6/25/2017 2:23 PM, Arne Vajhøj wrote:
>> On 6/25/2017 6:31 AM, Robert Klemme wrote:
>>> [...]
>>> A few minor remarks: brackets around comparisons are not needed.
>>
>> Not necessary.
>>
>> But actually recommended in the traditional Java coding convention.
>>
>> <quote>
>> 10.5.1 Parentheses
>>
>> It is generally a good idea to use parentheses liberally in 
>> expressions involving mixed operators to avoid operator precedence 
>> problems. Even if the operator precedence seems clear to you, it might 
>> not be to others-you shouldn't assume that other programmers know 
>> precedence as well as you do.
>>
>>      if (a == b && c == d)     // AVOID!
>>      if ((a == b) && (c == d)) // RIGHT
>>
>> </quote>
> 
>      Is anybody aware of any actual research into the value of
> this "generally good" practice, or does "generally good" merely
> mean "it's my prejudice, so as author I'll claim it's good?"

Many of these best practices are very hard to empirically
prove.

So it end up with whether you trust the people preaching
the best practice.

This one is also in McConnell's Code Complete.

Section 31.2:

<quote>
Use more parentheses than you think you need. Use parentheses to
clarify expressions that involve more than two terms. They may
not be needed, but they add clarity and they don't cost you anything.
</quote>

I have noticed that it is a very common problem among
beginner programmers to get unexpected results due to lack
of parentheses. For whatever reason SQL seems particular
prone to this error.

Whether you would let your coding style influence by:
* The gentleman Peter King, Patrick Naughton, Mike DeMoney,
   Jonni Kanerva, Kathy Walrath, and Scott Hommel from SUN
   (that apperently contributed to Java coding convention)
* McConnel
* a random dude on the internet: me
is up to you.

Arne



Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to handle same sanity checks Cecil Westerhof <Cecil@decebal.nl> - 2017-06-22 11:10 +0200
  Re: How to handle same sanity checks Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-22 10:27 +0000
    Re: How to handle same sanity checks Cecil Westerhof <Cecil@decebal.nl> - 2017-06-22 13:21 +0200
    Re: How to handle same sanity checks Cecil Westerhof <Cecil@decebal.nl> - 2017-06-23 06:51 +0200
    Re: How to handle same sanity checks Robert Klemme <shortcutter@googlemail.com> - 2017-06-24 12:06 +0200
      Re: How to handle same sanity checks Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-24 10:33 +0000
        Re: How to handle same sanity checks Robert Klemme <shortcutter@googlemail.com> - 2017-06-24 16:46 +0200
          Re: How to handle same sanity checks Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-24 19:37 +0000
  Re: How to handle same sanity checks Andreas Leitgeb <avl@logic.at> - 2017-06-22 11:26 +0000
    Re: How to handle same sanity checks Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-06-22 07:44 -0400
      Re: How to handle same sanity checks Andreas Leitgeb <avl@logic.at> - 2017-06-22 12:30 +0000
  Re: How to handle same sanity checks Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-06-22 07:40 -0400
    Re: How to handle same sanity checks v_borchert@despammed.com (Volker Borchert) - 2017-06-22 18:33 +0000
      Re: How to handle same sanity checks Cecil Westerhof <Cecil@decebal.nl> - 2017-06-23 06:48 +0200
        Re: How to handle same sanity checks Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-06-23 09:57 -0400
          Re: How to handle same sanity checks Cecil Westerhof <Cecil@decebal.nl> - 2017-06-23 16:31 +0200
            Re: How to handle same sanity checks Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-23 17:21 +0000
              Re: How to handle same sanity checks Eric Douglas <e.d.programmer@gmail.com> - 2017-06-26 05:21 -0700
                Re: How to handle same sanity checks Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-26 13:34 +0000
                Re: How to handle same sanity checks Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-26 15:22 +0000
        Re: How to handle same sanity checks Arne Vajhøj <arne@vajhoej.dk> - 2017-06-25 22:55 -0400
  Re: How to handle same sanity checks Marcel Mueller <news.5.maazl@spamgourmet.org> - 2017-06-22 23:07 +0200
  Re: How to handle same sanity checks Joerg Meier <joergmmeier@arcor.de> - 2017-06-25 09:52 +0200
  Re: How to handle same sanity checks Robert Klemme <shortcutter@googlemail.com> - 2017-06-25 12:31 +0200
    Re: How to handle same sanity checks Arne Vajhøj <arne@vajhoej.dk> - 2017-06-25 14:23 -0400
      Style police (Was: Re: How to handle same sanity checks) Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-06-25 17:28 -0400
        Re: Style police (Was: Re: How to handle same sanity checks) Arne Vajhøj <arne@vajhoej.dk> - 2017-06-25 19:14 -0400
        Re: Style police (Was: Re: How to handle same sanity checks) Arne Vajhøj <arne@vajhoej.dk> - 2017-06-25 19:19 -0400
          Re: Style police (Was: Re: How to handle same sanity checks) Robert Klemme <shortcutter@googlemail.com> - 2017-06-26 23:34 +0200

csiph-web