Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #29621

Re: in1To10

From "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org>
Newsgroups comp.lang.java.programmer
References <0c8de66a-429a-4697-b575-35f37a7b6882@googlegroups.com>
Subject Re: in1To10
Date 2014-08-10 13:53 +0100
Message-ID <M-6dnTFSjNeO9nrOnZ2dnUVZ8rednZ2d@bt.com> (permalink)

Show all headers | View raw


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). 

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

in1To10 cdalten@gmail.com - 2014-08-09 12:12 -0700
  Re: in1To10 Jeff Higgins <jeff@invalid.invalid> - 2014-08-09 15:58 -0400
  Re: in1To10 Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-09 16:13 -0400
  Re: in1To10 Marcel Mueller <news.5.maazl@spamgourmet.org> - 2014-08-09 22:56 +0200
    Re: in1To10 Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-09 17:02 -0400
      Re: in1To10 Marcel Mueller <news.5.maazl@spamgourmet.org> - 2014-08-09 23:43 +0200
        Re: in1To10 Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-09 19:49 -0400
        Re: in1To10 Torsten Kirschner <torsten@kirschner.no> - 2014-08-10 16:59 +0200
          Re: in1To10 Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-10 11:33 -0400
            Re: in1To10 Torsten Kirschner <torsten@kirschner.no> - 2014-08-11 22:23 +0200
            Re: in1To10 Gene Wirchenko <genew@telus.net> - 2014-08-12 11:10 -0700
              Re: in1To10 Arne Vajhøj <arne@vajhoej.dk> - 2014-08-19 16:54 -0400
                Re: in1To10 Gene Wirchenko <genew@telus.net> - 2014-08-20 10:36 -0700
            Re: in1To10 Arne Vajhøj <arne@vajhoej.dk> - 2014-08-19 16:53 -0400
  Re: in1To10 cdalten@gmail.com - 2014-08-09 18:35 -0700
    Re: in1To10 Jeff Higgins <jeff@invalid.invalid> - 2014-08-09 22:13 -0400
    Re: in1To10 Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-09 22:23 -0400
    Re: in1To10 Jeff Higgins <jeff@invalid.invalid> - 2014-08-10 12:07 -0400
  Re: in1To10 Mike Amling <mamling@chaff.us> - 2014-08-10 00:29 -0500
  Re: in1To10 "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-08-10 13:53 +0100
    Re: in1To10 Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-10 09:48 -0400
      Re: in1To10 "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-08-10 15:01 +0100
        Re: in1To10 Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-10 10:32 -0400
          Re: in1To10 "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-08-10 15:53 +0100
  Re: in1To10 lipska the kat <lipskathekat@example.com> - 2014-08-10 14:07 +0100
  Re: in1To10, a simple test plan lipska the kat <lipskathekat@example.com> - 2014-08-10 16:43 +0100
    Re: in1To10, a simple test plan Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-10 12:01 -0400
      Re: in1To10, a simple test plan lipska the kat <lipskathekat@example.com> - 2014-08-10 17:41 +0100
      Re: in1To10, a simple test plan Arne Vajhøj <arne@vajhoej.dk> - 2014-08-19 16:57 -0400
  Re: in1To10 Roedy Green <see_website@mindprod.com.invalid> - 2014-08-12 02:59 -0700

csiph-web