Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: [JLS] new long[0][ -1 ] Date: Fri, 10 Jul 2015 20:19:23 +0000 (UTC) Organization: A noiseless patient Spider Lines: 42 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Fri, 10 Jul 2015 20:19:23 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="e5160e2be48f1ea550cf61512446f525"; logging-data="1124"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/z39YV0C6Ka2Rxp34NLFulVvVJ2eHBC3Q=" User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Cancel-Lock: sha1:Hz/3eq3WCHUg+1qhHopSZa6LKLA= Xref: csiph.com comp.lang.java.programmer:31985 On Fri, 10 Jul 2015 14:19:24 +0000, Andreas Leitgeb wrote: > Eric Sosman wrote: >> You're welcome. But contemplating the uses of an array with >> fewer than zero elements has tied what remains of my brain in a knot >> that may not dissolve until my brain itself does ... :-) > > Some class's constructor gets passed two ints meaning width and height > of some rectangular grid. Currently, the only argument-sanitization is > to create a two dimensional array with it. Any exceptions caused by bad > arguments to "new int[ height ][ width ]" will be seen by client-code. > > My concern was, that a negative width might pass undetected after a zero > height. As is now clear: it doesn't, so it's all fine for me. I don't > care what exceptions are thrown back for bogus arguments, as long as all > bogosity ends in some exception right on the spot. > >> What use might we make of a minus-sized array? >> Perhaps it could model the old joke about a biologist, an engineer, and >> a mathematician at a sidewalk cafe. They see two people enter a >> building across the street, and a little later three people emerge. >> "They have reproduced," says the biologist. "Observational error," says >> the engineer. And the mathematician observes "If somebody now goes >> inside, the building will be empty." > > Too bad, arrays are fixed-size, so we cannot even add elements to make > it zero-sized. ;-) > Two features I'd have liked to see in Java are non-zero based arrays, e.g. int temperatureOcurrences[-40:55] and flexible array bounds, e.g int samples[0:flex] Neither are new ideas, both dating from the '60s: Algol 60 had non-zero- based fixed size arrays and Algol 68 implemented both concepts: both are useful in some circumstances as is multi-dimensional array slicing (Algol 68 had that too). -- martin@ | Martin Gregorie gregorie. | Essex, UK org |