Path: csiph.com!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: Comparison structure? Date: Tue, 4 Oct 2016 20:03:43 -0400 Organization: Aioe.org NNTP Server Lines: 40 Message-ID: References: <59c17fe5-61a6-46dc-918f-ee5aa348e3fd@googlegroups.com> 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:45.0) Gecko/20100101 Thunderbird/45.3.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:35720 On 10/4/2016 10:25 AM, Eric Douglas wrote: > I used some hard coded values to make a test block that compiles. > Suffice to say these are dynamically assigned. The 3-way IF block sounds > messy. Is there a better structure? > > int compareMe = 1; > int compareTo = 2; > final int assignMe; > if (compareMe == compareTo) { > assignMe = 4; > } else { > if (compareMe > compareTo) { > assignMe = compareMe + 2; > } else { > assignMe = compareMe; > } > } It is all about readability. That code is very readable. The reader easily understand what the code does. Good code in my opinion. I would flatten it like: int compareMe = 1; int compareTo = 2; final int assignMe; if (compareMe == compareTo) { assignMe = 4; } else if (compareMe > compareTo) { assignMe = compareMe + 2; } else { assignMe = compareMe; } but that is just a minor change. Arne