Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!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 09:48:04 -0400 Organization: A noiseless patient Spider Lines: 28 Message-ID: References: <0c8de66a-429a-4697-b575-35f37a7b6882@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 10 Aug 2014 13:48:05 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="bd4e1cba8d8592bec5d5ed9e4537fbfd"; logging-data="21054"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hW8TlFLlKxW+kDY/GgmQI" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.0 In-Reply-To: Cancel-Lock: sha1:fqcz7tqZGIb3jwOs+zaQUTlZKmU= Xref: csiph.com comp.lang.java.programmer:29623 On 8/10/2014 8:53 AM, Chris Uppal wrote: > cdalten@gmail.com wrote: > >> The problem states: "Given a number n, return true if n is in the range >> 1..10, inclusive. Unless "outsideMode" is true, in which case return true >> if the number is less or equal to 1, or greater or equal to 10." > > Not really addressing the question, but nobody (I've seen) has mentioned what I > would consider the most direct encoding of the problem which has IMO the most > "eloquent" use of Boolean-valued variables. It also, IMO, illustrates the need > for /very carefully/ considered identifiers[*] (which for some reason seems to > be at its most acute for Booleans -- I have no idea why, anyone ?). > > Not tested. Some might prefer more brackets. > > static boolean testAgainst1to10(int i, boolean trueIfOutside) > { > boolean isOutside = i < 1 || i > 10; > return isOutside == trueIfOutside; > } "Not really addressing the question" is a good opening, because the offered code addresses a different question than the one posed. (You've repeated Marcel Mueller's mistake, perhaps by reading a little too quickly.) -- esosman@comcast-dot-net.invalid