Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.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: Re: in1To10 Date: Sun, 10 Aug 2014 11:33:17 -0400 Organization: A noiseless patient Spider Lines: 37 Message-ID: References: <0c8de66a-429a-4697-b575-35f37a7b6882@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 10 Aug 2014 15:33:18 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="bd4e1cba8d8592bec5d5ed9e4537fbfd"; logging-data="4179"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19H5CmmfqVw9TY4LlEB5vC7" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.0 In-Reply-To: Cancel-Lock: sha1:IEoNDQPmg/swo3D4H6k5AqOqVHA= Xref: csiph.com comp.lang.java.programmer:29629 On 8/10/2014 10:59 AM, Torsten Kirschner wrote: > Den 09.08.2014 23:43, skrev Marcel Mueller: >> On 09.08.14 23.02, Eric Sosman wrote: >>> Unfortunately, this cleaned-up version does not solve the >>> problem as specified. (Hint: What is `in1To10(1,true)'?) >> >> Oops, you are right, I read a bit fast. 1 and 10 should always return true. > > So... > > static boolean in1To10(int n, boolean outsideMode) { > > if (n == 1 || n == 10) > return true; > > return (n > 1 && n < 10) ^ outsideMode; > } Looks right to me. It could be abbreviated: return n == 1 || n == 10 || ((n > 1 && n < 10) ^ outsideMode); ... but to my eye the clearest expression would be something like: return outsideMode ? (n <= 1 || n >= 10) : (n >= 1 && n <= 10); (I've seen coding standards that discourage the ?: operator on the grounds that "it's confusing," but to me that seems bogus. People who write such standards must hold a poor opinion of the people who will have to follow them, and I don't want to work with people who have such a poor opinion of me. Hiring a Java programmer who's confused by ?: would be like hiring a tone-deaf violinist.) -- esosman@comcast-dot-net.invalid