Path: csiph.com!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!multikabel.net!newsfeed20.multikabel.net!post40.multikabel.net!cache80.multikabel.net!not-for-mail From: "Skybuck Flying" Newsgroups: alt.comp.lang.borland-delphi,comp.lang.c,comp.lang.java.programmer References: <29308868.1994.1337265697084.JavaMail.geo-discussion-forums@pbcuc6> <84131$4fb54067$5419acc3$20839@cache90.multikabel.net> In-Reply-To: Subject: Re: Oracle/Google demonstrate human beings cannot write 10 lines of code without making a mistake ;) Date: Sun, 20 May 2012 17:53:27 +0200 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal Importance: Normal X-Newsreader: Microsoft Windows Live Mail 15.4.3538.513 X-MimeOLE: Produced By Microsoft MimeOLE V15.4.3538.513 Message-ID: <1bd38$4fb91376$5419acc3$14683@cache80.multikabel.net> X-Complaints-To: abuse@ziggo.nl Organization: Ziggo Lines: 59 NNTP-Posting-Host: 84.25.172.195 (84.25.172.195) NNTP-Posting-Date: Sun, 20 May 2012 17:53:26 +0200 X-Trace: 1bd384fb91376f1bc096614683 Xref: csiph.com comp.lang.c:21067 comp.lang.java.programmer:14673 "glen herrmannsfeldt" wrote in message news:jp3g9r$v22$1@speranza.aioe.org... In comp.lang.java.programmer Skybuck Flying wrote: (snip) >>> if (fromIndex < 0) >>> throw new ArrayIndexOutOfBoundsException(fromIndex); >>> if (toIndex > arrayLen) >>> throw new ArrayIndexOutOfBoundsException(toIndex); (snip, someone else wrote) >> I believe it is checking whether the range fromIndex, fromIndex+1, ..., >> toIndex-1 -- i.e., a range given as the first index and one past the >> last index, not an uncommon practice -- is within the array, in which >> case it has no bugs. (toIndex may legally equal the length of the array >> when the range extends to the last element, and requiring the range to >> be specified "the right way around" is not especially perverse.) >> " > It's simply not valid. Out of bounds has a very clear meaning > in programming practice. It's either within bounds or it's not. But this isn't "programming" it is Java, and Java can do it however it wants to. > The bounds of a java array are very clearly defined. Thus the > only logical conclusion is that the code is simply bugged. > Either in logic or in description. Either change the > exception-description or fix the code. " Look at the definition of the substring method in String class. " String might/could be an exception, but me not interested in strings so much. " It avoids a lot of -1 by the programmer to define it this way. (Along with consistently starting indexing at zero.) " The -1 is what keep programs correct. It's the lack of -1 that will ultimately lead to bugs, confusion and problems ! ;) :) Not to mention wrong ranges ! ;) Learn to use -1 consistently and all will be fine ! ;) :) =D Bye, Skybuck.