Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!news.mixmin.net!aioe.org!.POSTED!not-for-mail From: glen herrmannsfeldt Newsgroups: alt.comp.lang.borland-delphi,comp.lang.c,comp.lang.java.programmer Subject: Re: Oracle/Google demonstrate human beings cannot write 10 lines of code without making a mistake ;) Date: Thu, 17 May 2012 18:33:31 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 37 Message-ID: References: <29308868.1994.1337265697084.JavaMail.geo-discussion-forums@pbcuc6> <84131$4fb54067$5419acc3$20839@cache90.multikabel.net> NNTP-Posting-Host: H0vc4U5LIRkRHNPyGCs2dA.user.speranza.aioe.org X-Complaints-To: abuse@aioe.org User-Agent: tin/1.9.6-20100522 ("Lochruan") (UNIX) (Linux/2.6.32-5-amd64 (x86_64)) X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.c:20924 comp.lang.java.programmer:14589 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. It avoids a lot of -1 by the programmer to define it this way. (Along with consistently starting indexing at zero.) -- glen