Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: Arithmetic overflow checking Date: Sat, 09 Jul 2011 07:46:45 -0700 Organization: A noiseless patient Spider Lines: 29 Message-ID: References: <015aeb15-57db-48ab-9cd4-77f8448b632f@w24g2000yqw.googlegroups.com> <2rydnez7l-H5BYnTnZ2dnUVZ_vGdnZ2d@earthlink.com> <9LWdnZH2hdfmyYvTnZ2dnUVZ_vidnZ2d@posted.palinacquisition> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 9 Jul 2011 14:46:51 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="5HSAJfqnDjjLFxXZ6WBWEw"; logging-data="22118"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18NUdMJA+Tctv0BdOeqORcSSMOLQiBfjfk=" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 In-Reply-To: Cancel-Lock: sha1:7UoMkc3vCiDbVF5csdRZDrjBJlw= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6018 On 7/9/2011 2:58 AM, rop rop wrote: > I also think not, in the general case... > But you could also have an annotation argument, like > > @CheckForOverflow(allTheWayDown=true) > or > @CheckForOverflow(allTheWayDown=false) I did a quick check of the C# variant when it was mentioned here, and this is how they do it: int result = checked( a + b - c ); In other words is a key word. Since Java can't really do this easily, I'd be in favor of using an existing key word and extending it. For example, the key word "try" can't ever appear currently as a class name or package name in any program, so we could do this: int result = try.checked( a + b - c ); Which at least makes sense to me as one reads the code; i.e., it's literate programming. One could, I suppose, also extend the syntax where an annotation can be used, but this might have side effects also. For example, it might be hard to support these new user defined annotations in the general case.