Path: csiph.com!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: How to handle same sanity checks Date: Sun, 25 Jun 2017 14:23:18 -0400 Organization: Aioe.org NNTP Server Lines: 31 Message-ID: References: <87o9tgo0a9.fsf@munus.decebal.nl> NNTP-Posting-Host: PBuS014lhzVyHjLbXmo/ZQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Language: en-US Xref: csiph.com comp.lang.java.programmer:36721 On 6/25/2017 6:31 AM, Robert Klemme wrote: > On 22.06.2017 11:10, Cecil Westerhof wrote: >> In my code I have several methods that start with: >> if ((n < MIN_VAL) || (n > MAX_VAL)) { >> throw new InvalidParameterException(String.format(ERROR_N, n)); >> } >> >> That is not really DRY. > > 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 Arne