Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!news.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 12 May 2011 15:45:17 -0500 Date: Thu, 12 May 2011 13:45:07 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Java puzzler References: <4db69c13-878f-4806-adb2-a3c5adb1c48c@glegroupsg2000goo.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <-8mdnSRPEIdA21HQnZ2dnUVZ_j2dnZ2d@earthlink.com> Lines: 38 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 75.8.126.96 X-Trace: sv3-hIjcs9OyBpRYbk88cnJz6KSMFlXrS3gmaGlgt/7B+tdlm5bSj5+MS9P6oPyOHbVVQIA/2VljIgDutKu!tgObYkwBLVdOlEydEVSBIIXJ7nT5CkU6yL8/Xg1qeg37vpvDEzaxawoG4qYUBgtijjBsHV6OPHBg!+6YE4fm8CgGEXEj3fkVoeGb0G+krwsyaJq4WTv8oDIM= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2880 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:4023 On 5/12/2011 1:38 PM, Tom Anderson wrote: > On Wed, 11 May 2011, Patricia Shanahan wrote: > f >> On 5/11/2011 1:57 PM, Tom Anderson wrote: >>> On Wed, 11 May 2011, Patricia Shanahan wrote: >> ... >>>> Without the implicit cast to the left hand side type, "+=" could not >>>> have been used for byte, char, or short. The arithmetic operation >>>> promotes to int, and there would be no way to cast back to the target >>>> type. >>> >>> Well, that's true if one takes as given that the operation promotes to >>> int. Could it have been specified not to? >> >> Sure, but that would create other weirdness. For example: >> >> byte b = 100; >> byte c = 100; >> int i = b + c; >> >> would assign -56 to i, because that is the byte result of the addition. > > Okay, i've changed my mind. > > Instead, all arithmetic operations, and all casts, should throw an > exception if they overflow. Then, if a string of operations does not do > anything surprising, the matter of casting is moot, and if they do, they > blow up, so it is also moot. If we were starting from scratch, that would be an option. To do that effectively you need a full set of signed and unsigned data types, or, better still, arithmetic types with arbitrary value ranges. It would be a step towards Ada, rather than Java's predominantly C and C++ heritage. As it is, it would break far too much code to be possible as a change to the existing language. Patricia