[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Arithmetic overflow [was Re: the benefits of immutability]
On Wednesday, August 20, 2003, at 11:49 AM, James Y. Knight wrote:
> On Tuesday, August 19, 2003, at 04:09 PM, Perry E. Metzger wrote:
>> The pathetic thing about Java is that not only is it crippled to make
>> it safe, but it isn't even safe. Overflows, for example, are ignored,
>> presumably to make it look more like C. Yuck.
>
> You're talking about a different definition of safe. Java is safe in
> that you can safely run random code downloaded off the internet on
> your local machine without it being able to send out spam to everyone
> on the planet, upload all your personal information to the author, and
> then erase your hard drive. It is not safe against writing incorrect
> code. However, it does have many features that make it *easier* to
> write correct code (e.g. garbage collection, required exception
> handling).
That's not save, that's secure.
Safe: the language doesn't interpret bits from one set of values as if
they belonged to a different one,
where "set of values" is defined at the syntactic level. Examples of
safe languages: PLT Scheme, Java.
Examples of unsafe languages: C++, Modula III's unsafe modules.
Secure: the language tailors the set of primitive computational
operations so that a program can affect
its environment only in a well-specified way.
Java's choice for implementing numbers is one of many possibly sound
and safe choices. Just keep
in mind that every numeric program "lies" to you when it gives you an
answer in languages that make
Java's choice.
Question from an exam for entry-level programmers that 90++% get/got
wrong:
What data type should you use to represent amounts of money in a
program?
-- Matthias