From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,fee8802cc3d8334d X-Google-Attributes: gid103376,public X-Google-Thread: 10a146,fee8802cc3d8334d X-Google-Attributes: gid10a146,public From: Mark Hood Subject: Re: Ada and Java. different behaviour. casting long to int problem. Date: 1999/06/16 Message-ID: #1/1 X-Deja-AN: 490459419 References: <7jt2c0$vrb@drn.newsguy.com> <7k57vb$1ipf@drn.newsguy.com> <3766650F.705125B7@pwfl.com> Organization: Sun Microsystems Inc., Mountain View, CA Newsgroups: comp.lang.ada,comp.lang.java.programmer Date: 1999-06-16T00:00:00+00:00 List-Id: Marin David Condic writes: > > I'm of the opinion that if one wishes behavior different from that of > "normal" arithmetic, then this should be specified by a type with > special properties. > [...] > If one wants wraparound semantics, then perhaps there should be a special > type to support that behavior - a la modular types in Ada. I agree with this line of thinking, except that I think that the Java primitive types ought to be left alone, and that specialized classes written to more closely emulate the behavior of mathematical integers would be the appropriate solution to these issues. The whole point of Java primitive types such as int, long, and double is that are *primitives*, ie, very close to the actual representations used by the virtual machine. They are exposed to the programmer because there are some real advantages to working at that level, such as increased performance. It is of course completely feasible to wrap the primitive types in objects which provide more safety and convenience for the programmer, and this is exactly the intent of the Integer, Long, and Double classes. These could certainly be extended to check for overflows by any programmer who thinks that would be desirable for the project at hand. The argument has also been made that lack of overflow detection is as onerous to quality code as the use of explicit pointers and the lack of array bounds checking. I disagree; the former has the possibility of corrupting individual data values, while the latter carries the risk of disrupting the integrity of the entire structure used to represent the data, as well as the state of the virtual machine itself. Providing programmers access to primitive data types is a reasonable compromise between safety and efficiency in my opinion. -- Mark Hood