Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Jim Janney 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: Wed, 23 May 2012 08:46:57 -0600 Organization: he sent them word I had not gone Lines: 44 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx04.eternal-september.org; posting-host="PnllQd880uOddfy6hsxHuQ"; logging-data="3568"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+2ZRX6sNpyKZVK6JDTe1Xw" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:uf97Row+IlXEcwC5ONbslC5wyrU= sha1:hz4UOJswgNDL6SrAxNhGiVp2gec= Xref: csiph.com comp.lang.c:21240 comp.lang.java.programmer:14756 falk@rahul.net (Edward A. Falk) writes: > In article , > Skybuck Flying wrote: >> >>" >>private static void rangeCheck(int arrayLen, int fromIndex, int toIndex) { >> if (fromIndex > toIndex) >> throw new IllegalArgumentException("fromIndex(" + fromIndex + >> ") > toIndex(" + toIndex+")"); >> if (fromIndex < 0) >> throw new ArrayIndexOutOfBoundsException(fromIndex); >> if (toIndex > arrayLen) >> throw new ArrayIndexOutOfBoundsException(toIndex); >>} >>" > > Executive summary: If the indices here are used as [fromIndex toIndex) -- > that is, inclusive-exclusive -- as is often the custom, *and* a > zero-length range is permitted, then this code is correct as written. > > Plus, if this was a commonly-used code fragment, any error would have > turned up long ago. > > Finally, the keyword "private" means that this function is unavailable > outside of the file that defines it. There would be no reason to document > it. There would also be no reason to hold it to any standard other than > that it perform the specific function for which it was intended. Without > seeing the functions or methods that call it, there's really no true way > to know if it's buggy or not. The complete code is available for inspection: it's distributed with every copy of the JDK, and can also be found on the web at many places, for example: http://cr.openjdk.java.net/~martin/webrevs/openjdk7/timsort/src/share/classes/java/util/TimSort.java.html And as has been pointed out before, the function *is* documented and the implementation matches its contract exactly. It's not a bug. Period. -- Jim Janney