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


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

Re: How to check if the n-th part of an array of Strings exist?

From Eric Sosman <esosman@ieee-dot-org.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: How to check if the n-th part of an array of Strings exist?
Date 2011-10-27 21:25 -0400
Organization A noiseless patient Spider
Message-ID <j8d0c5$uj2$1@dont-email.me> (permalink)
References (1 earlier) <mn.d5897dba40f6378a.70216@a.com> <qot62jahpek.fsf@ruuvi.it.helsinki.fi> <j8bf5f$b8i$1@dont-email.me> <htlia7donph3mi48evn2l5qi2ini8rbn7a@4ax.com> <4ea95fbd$0$631$426a74cc@news.free.fr>

Show all headers | View raw


On 10/27/2011 9:45 AM, Mayeul wrote:
> On 27/10/2011 15:09, Tim Slattery wrote:
>> Eric Sosman<esosman@ieee-dot-org.invalid> wrote:
>>
>>> On 10/27/2011 3:20 AM, Jussi Piitulainen wrote:
>>>> Wojtek writes:
>>>>
>>>>> You check for the number of "slots" in the array:
>>>>>
>>>>> if ( index>= 0&& index< part.length )
>>>>> do something with part[index]
>>>>> else
>>>>> error();
>>>>
>>>> Shame that (0<= index< part.length) means something useless instead.
>>>
>>> Be thankful that its meaning in Java is more useful than in C.
>>
>> Please explain that. I'm probably wrong, but I'd think they'd be the
>> same.
>>
>> Evaluate one of the comparisons (not positive which one), resulting in
>> a boolean. Convert the boolean to a number to do the other comparison.
>> Not very useful.
>>
>
> I'd wager that refusing to compile is more useful than meaning something
> useless and confusing, therefore errors-prone.

     Bingo.  (That at least is what I meant; whether it's "true" is
another matter entirely.)

     In C, `x < y < z' has a well-defined meaning, but one that is so
very unlikely to be intended that it is almost surely a mistake.  The
meaning is: "Compare x to y, yielding 1 if x is in fact less than y
or 0 if not. Then compare that 1 or 0 to z, yielding 1 if it is less
than z or 0 if it is not."

     If z is not in (0,1] the expression's value is foreordained as
0 (for z <= 0 or z a NaN) or 1 (for z > 1).  An expression with a
foreordained value is, I think, deserving of being called "useless."

     If z is in (0,1] The expression `x < y < z' is equivalent to
`!(x < y)', which is in turn equivalent to `x >= y' if NaN's are
not involved.  Either of the latter two forms is, I'd say, greatly
preferable, and the original is "useless" because it would be better
written in one of the other ways.

     In Java `x < y < z' is a compile-time error.

     That's why I think Java's interpretation is superior.  Not that
Java gets *everything* right: If x,y,z are booleans `x == y == z'
is valid and means something other than what might be expected.
Still, it's an improvement on C.

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

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


Thread

How to check if the n-th part of an array of Strings exist? jochen2@brenz.com (Jochen Brenzlinger) - 2011-10-25 16:26 +0000
  Re: How to check if the n-th part of an array of Strings exist? Tom McGlynn <taqmcg@gmail.com> - 2011-10-25 09:41 -0700
  Re: How to check if the n-th part of an array of Strings exist? Wojtek <nowhere@a.com> - 2011-10-26 23:37 -0700
    Re: How to check if the n-th part of an array of Strings exist? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2011-10-27 10:20 +0300
      Re: How to check if the n-th part of an array of Strings exist? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-10-27 07:26 -0400
        Re: How to check if the n-th part of an array of Strings exist? Tim Slattery <Slattery_T@bls.gov> - 2011-10-27 09:09 -0400
          Re: How to check if the n-th part of an array of Strings exist? Mayeul <mayeul.marguet@free.fr> - 2011-10-27 15:45 +0200
            Re: How to check if the n-th part of an array of Strings exist? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2011-10-27 16:55 +0300
            Re: How to check if the n-th part of an array of Strings exist? Gene Wirchenko <genew@ocis.net> - 2011-10-27 10:37 -0700
              Re: How to check if the n-th part of an array of Strings exist? Tassilo Horn <tassilo@member.fsf.org> - 2011-10-27 21:31 +0200
            Re: How to check if the n-th part of an array of Strings exist? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-10-27 21:25 -0400
              Re: How to check if the n-th part of an array of Strings exist? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2011-10-28 10:08 +0300
  Re: How to check if the n-th part of an array of Strings exist? Roedy Green <see_website@mindprod.com.invalid> - 2011-10-28 06:20 -0700
  Re: How to check if the n-th part of an array of Strings exist? Arne Vajhøj <arne@vajhoej.dk> - 2011-11-06 14:54 -0500

csiph-web