Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.roellig-ltd.de!open-news-network.org!feed.xsnews.nl!fbe002.ams.xsnews.nl!ecngs!feeder.ecngs.de!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Sun, 10 Aug 2014 07:52:35 -0500 From: "Chris Uppal" Newsgroups: comp.lang.java.programmer References: <0c8de66a-429a-4697-b575-35f37a7b6882@googlegroups.com> Subject: Re: in1To10 Date: Sun, 10 Aug 2014 13:53:23 +0100 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5512 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512 Message-ID: Lines: 27 X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-6Jguf7pvQCxYUReLJ8b3dqmxLeFAV9kFy5SwGlp7kScSuJNgh9OiLSnvRVZ2DqRc5uRG/5TGJzBoZmR!7Gj6DZWGmVUk7XIFN/ydXzawO8fg0TG1PYN8cMn+bL2M3Wl0fPJWZPIqStL9Hf7smpNgNEZolw== X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2227 Xref: csiph.com comp.lang.java.programmer:29621 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; } -- chris [*] Not that I'm claiming that my choices of names /are/ especially good -- on the contrary I claim that there cannot /be/ any really good names for such a wildly artificial challenge (but I've done the best I can).