Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: Help with Deck of cards assignment and getting it to deal... Date: Mon, 4 Aug 2014 13:00:20 +0000 (UTC) Organization: A noiseless patient Spider Lines: 38 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Mon, 4 Aug 2014 13:00:20 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="e5160e2be48f1ea550cf61512446f525"; logging-data="21502"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/OC53t1TZ2OZLSC5CjbXDb+6LGN2w2nUU=" User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Cancel-Lock: sha1:XXLs3Ng/R/bAtyEIsCyO2zmWSvg= Xref: csiph.com comp.lang.java.programmer:29555 On Sun, 03 Aug 2014 15:54:52 -0700, Roedy Green wrote: > On Sat, 2 Aug 2014 10:19:42 +0000 (UTC), Martin Gregorie > wrote, quoted or indirectly quoted > someone who said : > > >>In Java the indices of an array start to zero, not 1. Assuming that they >>start from 1, as you've done, will almost certainly cause problems at >>runtime by throwing "index out of range" exceptions. > > http://mindprod.com/jgloss/pseudorandom.html > > I scanned the page, but I could not find an example where your comment > applies. I showed you how to generate a random number in the bounds low > .. high, but other than that all the others start at 0. > > Could you please give me the context of the error, or perhaps you were > referring to something OP or another poster said. > Looking at the double loop scanning suits and card ranks (both 1-based) and using these ranges to control array filling made my teeth itch. OK, he generated the deck index separately, but it just struck me as a bad practice to get used to when you're using languages like C or Java with a fixed zero lower bound for arrays. BTW: there's another Java flaw that nobody has yet mentioned: why is there a primitive array type, especially now we have generics? Surely an array should be an object containing the element list as well as the upper and lower bounds. It should also provide methods that return the bounds: the ability to set array bounds to suit the natural index range of the data in the array is very helpful for writing clear code. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |