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: 10a146,fee8802cc3d8334d X-Google-Attributes: gid10a146,public X-Google-Thread: 103376,fee8802cc3d8334d X-Google-Attributes: gid103376,public From: Samuel Mize Subject: Re: Ada and Java. different behaviour. casting long to int problem. Date: 1999/06/15 Message-ID: <7k6ej3$23kg@news1.newsguy.com>#1/1 X-Deja-AN: 490014234 References: <7jt2c0$vrb@drn.newsguy.com> <7k57vb$1ipf@drn.newsguy.com> <3766650F.705125B7@pwfl.com> <7k64t7$igo$1@its.hooked.net> <7k689a$ci2@drn.newsguy.com> Organization: ImagiNet Communications, Ltd. User-Agent: tin/pre-1.4-981002 ("Phobia") (UNIX) (AIX/3-2) Newsgroups: comp.lang.ada,comp.lang.java.programmer Date: 1999-06-15T00:00:00+00:00 List-Id: In comp.lang.ada rich@nowhere.com wrote: > In article <7k64t7$igo$1@its.hooked.net>, "Mike says... >> >>I agree completely. To my mind, quietly producing a non-intuitive result >>(via truncation or wraparound) is in the same league as being able to >>quietly step off the end of an array (something the Java folks beat up on >>the C/C++ folks about constantly). ... >one can reply: as long as the language is defined to behave > this way, it becomes the programmer resposibility, and any unexpected > behaviour resulting from using such language means the programmer is > incompetent. I'd like to make my opinion a little clearer than that! Getting an exception is usually BETTER. But it's no more abstractly correct than wrapping around or truncating. ANY efficient representation is going to compromise the abstraction "integer." When you add two abstract integers, wrapping around is wrong; truncating is wrong; raising an exception is wrong. I have yet to see a math book that discussed exceptions! There are times where each of these is right, or at least useful. And, there are times when each of them can cause problems. The ideal language would make all three options available, at the programmer's discretion. Say -- Ada does that! If you overload the functions yourself, so does Java. So I'd agree that Ada is more convenient, and that its default behavior is more likely to be what a math-trained user would expect. That doesn't make Java and C "wrong," just harder to use well. > So, as long as C/C++ is defined not to do array boundary checking (which > it is), then no one has the right to critisize such languages, No, I'd say you have every right to criticize the language. I just wouldn't say the language is WRONG. I'd say it's weaker, that it helps you less, and that it has a more primitive model of arrays. > then it becomes the resposibility of the programmer to understand this, > and a programmer that produces a program that fails to check everywhere > for this, is an incompetent programmer. If we're talking about someone who writes software assuming that no computation will exceed the bounds of the representation, without any analysis, then "incompetent" is probably fair. Whether it produces a wrong number or just crashes, it will fail in a spectacular way after delivery. But note that in the example of a bank account, a bad result will require some kind of corrective transaction, while an unhandled exception may cause a crash, leaving parts of the bank's system in an undefined state. Putting in exception handlers that would keep the transaction correct will require as much analysis as if you were using Java and had to avoid wrap-around. In short, I think that calling Java/C "wrong" is unfair here, as unfair as complaining that a harpoon makes a bad hammer. But it's certainly fair to say that more people need hammers than harpoons! Best, Sam Mize -- Samuel Mize -- smize@imagin.net (home email) -- Team Ada Fight Spam: see http://www.cauce.org/ \\\ Smert Spamonam