Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Style police (Was: Re: How to handle same sanity checks) Date: Sun, 25 Jun 2017 17:28:26 -0400 Organization: A noiseless patient Spider Lines: 37 Message-ID: References: <87o9tgo0a9.fsf@munus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sun, 25 Jun 2017 21:24:44 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="a5f3c3584a1d280f80d637147495788d"; logging-data="30353"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+NAjeatowHMdpArnkrhne8" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 In-Reply-To: Content-Language: en-US Cancel-Lock: sha1:AujHBZIe2XLZfh9ng4sPtW2ycuk= Xref: csiph.com comp.lang.java.programmer:36722 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. > > > 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 > > 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?" I'll note in passing that the author is no Java Jedi. Consider section 10.4 of the same document, which recommends if ((c++ = d++) != 0) ... as an "improvement" over an equally uncompilable bad example. -- esosman@comcast-dot-net.invalid Thirteen hundred five days to go.