Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!goblin3!goblin.stu.neva.ru!newsfeed3.funet.fi!newsfeeds.funet.fi!news.helsinki.fi!.POSTED!not-for-mail From: Jussi Piitulainen Newsgroups: comp.lang.java.programmer Subject: Re: How to check if the n-th part of an array of Strings exist? Date: 28 Oct 2011 10:08:24 +0300 Organization: University of Helsinki Lines: 49 Sender: jpiitula@ruuvi.it.helsinki.fi Message-ID: References: <4ea6e340$0$6580$9b4e6d93@newsspool3.arcor-online.net> <4ea95fbd$0$631$426a74cc@news.free.fr> NNTP-Posting-Host: ruuvi.it.helsinki.fi Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: oravannahka.helsinki.fi 1319785704 8495 128.214.205.65 (28 Oct 2011 07:08:24 GMT) X-Complaints-To: usenet@oravannahka.helsinki.fi NNTP-Posting-Date: Fri, 28 Oct 2011 07:08:24 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9269 Eric Sosman writes: > On 10/27/2011 9:45 AM, Mayeul wrote: > > On 27/10/2011 15:09, Tim Slattery wrote: > >> Eric Sosman wrote: > >> > >>> On 10/27/2011 3:20 AM, Jussi Piitulainen wrote: > >>>> 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 ... > 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. Java does not get this right. It's merely a mild improvement on C. Python gets this right: 0 <= k < n means what one expects. Comparison chains are not hard to understand or implement: just add a syntactic category of relation symbols (<, >, <=, >=, ==, !=) with the same low precedence, associative, and give the resulting expression the intended meaning that everybody learns to expect in school. Since the current meaning of chained comparisons in Java is not useful for much anything, the change would not be impossible. This does not mean that I expect it to happen. I do not expect it to happen. The languages that get chained comparisons right have some bragging rights over Lisp. While Lisp does 0 < k < n with ease, it gets uneasy with the different comparisons in 0 <= k < n, which often is what one wants to test.