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: Fred@moon.com.spam_free Subject: Re: Ada and Java. different behaviour. casting long to int problem. Date: 1999/06/12 Message-ID: <7jvj7r$1nj8@drn.newsguy.com>#1/1 X-Deja-AN: 489015701 References: <7jt2c0$vrb@drn.newsguy.com> <7jv4bh$11rg@drn.newsguy.com> <7jvcqv$od9$1@nnrp1.deja.com> Newsgroups: comp.lang.ada,comp.lang.java.programmer Date: 1999-06-12T00:00:00+00:00 List-Id: In article <7jvcqv$od9$1@nnrp1.deja.com>, Robert says... > >> Ok, so the bottom line of all this, is that Java (and C and >> C++) all blew it, and Ada did not. > >I disagree strongly with this statement. Java has well defined >portable semantics for its arithmetic operations. It is the >programmers responsibility to know these semantics and use them >in an appropriate manner. > OK, so you are in the middle of lengthy calculation, with some intermediate results being generated on the fly, and an overflow occurs. In Java, nothing happens, and life goes on and the final number is wrong, but no one really knows it is wrong, or may be someone will notice it is wrong. In Ada, the overflow is detected the second it occurs, and the programmer can go and fix the calculation, or the data types for some of the variables involved. Your answer to all this, is that with Java, even if the final answer is wrong, it is OK, since that is how Java is defined to work, and the programmer, somehow must have anticipated every possible value that can occur, even in intermediate transit calculations to make sure no overflow will occur, and it is the fault of the programmer. You might be right actually. may be the programmer should have. but if you want to put your life on-line dependent on some program, which one of the above two language would you choose to write the software with? I know which one I'll choose. >A programmer who casually expects Java to check for overflow >in a situation where it is well defined that it does not is >incompetent, and it is unreasonable to blame Java for such >incompetence. ... >There is no basic error here in the Java case, just a >misunderstanding by the programmer. If you don't know the >rules of your language, you may well make a mess of things! Following your logic, no one in the Ada groups should ever criticize C++ or C any more, since C/C++ is well defined as well, even though the way it is defined can lead to problems, it is the responsibility of the programmer not to fall into these problems and it is not reasonable to blame C or C++ for such problems. When someone moves a long into a char in C, with loss of data, and the compiler and the run-time not detecting this, do not blame C then when that train crashes killing 50 people, Blame the programmer, becuase it is well defined in C that it is allowed to move long into a char. No thank you, I'd rather depend on a language defined to catch such errors, rather than depending on each programmer manually detecting such problems for each step of the program. humans do make mistakes, that is why we invent languages that are strongly typed to help programmers find such mistakes. Fred