Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #4116
| From | Tom Anderson <twic@urchin.earth.li> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Java puzzler |
| Date | 2011-05-15 15:23 +0100 |
| Organization | Stack Usenet News Service |
| Message-ID | <alpine.DEB.2.00.1105151513070.12373@urchin.earth.li> (permalink) |
| References | (12 earlier) <iqm848$52b$1@dont-email.me> <alpine.DEB.2.00.1105150033090.12373@urchin.earth.li> <iqnakv$t9g$1@dont-email.me> <alpine.DEB.2.00.1105151107130.12373@urchin.earth.li> <iqohjj$a0q$1@dont-email.me> |
On Sun, 15 May 2011, markspace wrote:
> On 5/15/2011 3:16 AM, Tom Anderson wrote:
>
>> Fair enough. I suppose my position is that this hardware ability has to
>> be used in the service of some solidly well-defined software semantics.
>> Throwing exceptions at random from arithmetic expressions is not what i
>> think of as solidly well-defined.
>
> I guess I'm not understanding what people think is wrong with the
> semantics of "overflow." Overflow is very well defined. It's something
> like 8 gates on the hardware level, and happens at the same speed as the
> the add or subtract itself. I.e., about 1 CPU cycle in most cases
> nowadays.
>
> By contrast, the current semantics of integer math are that sometimes
> you get the right answer and sometimes you don't. I consider that to be
> non-deterministic.
>
> Here's a method to sum a list of numbers:
>
> public int sum( int[] nums ) {
> int sum = 0;
> for( int n : nums ) sum += n;
> return sum;
> }
>
> What I want is for this to throw an error if it can't compute the sum
> correctly. How is that non-semantic, even slightly? How is the current
> implementation where sometimes this works and sometimes it doesn't even
> *slightly* semantic in comparison?
With the current semantics, for a given input - a given sequence of values
in nums - this code will always produce the same output, on all JVMs,
under all situations, optimised or not. That answer will sometimes be
utter rubbish, but it is consistently rubbish across all platforms. You
will recall that one of Java's earliest goals was just that - Write Once,
Rubbish Anywhere.
If the rules about overflow were as you want, which is roughly "if a
calculation carried out by the processor overflows, an exception is
thrown", then we would indeed no longer produce rubbish. But because
different machines - different processors, different compilers, different
applications of the same compiler - will carry out that calculation in
different ways (due to different hardware capabilities, and also having
made different choices about loop unrolling, use of SIMD instructions, use
of registers vs stores to the stack, etc), those hardware overflows will
happen differently. A given input will be successfully summed on one
machine, but will cause an exception on another machine. You now have
Write Once, Failure Somewhere (but Rubbish Nowhere).
You evidently feel that Rubbish Nowhere is a bigger win than Failure
Somewhere is a loss. Others do not.
What i was getting at with the infinite width stuff is the idea that you
might be able to define the semantics such that the results are still
consistent across all machines (now we've got Write Once, Right Anywhere).
But in doing so, you would constrain implementations so that they can't
optimise effectively. So you actually gave Write Once, Right Anywhere -
Slowly.
So basically, it's a matter of consistent, correct, quick - pick two.
tom
--
a moratorium on the future
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
Re: Java puzzler Gábor Bakos <aborgabor@gmail.com> - 2011-05-11 01:44 -0700
Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-11 05:24 -0700
Re: Java puzzler Tom Anderson <twic@urchin.earth.li> - 2011-05-11 21:57 +0100
Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-11 16:07 -0700
Re: Java puzzler Tom Anderson <twic@urchin.earth.li> - 2011-05-12 21:38 +0100
Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-12 13:45 -0700
Re: Java puzzler Nancy 3 <n3@gmai1.c0m> - 2011-05-12 16:56 -0400
Re: Java puzzler markspace <-@.> - 2011-05-12 14:32 -0700
Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-12 16:05 -0700
Re: Java puzzler markspace <-@.> - 2011-05-12 17:40 -0700
Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-12 18:18 -0700
Re: Java puzzler markspace <-@.> - 2011-05-12 19:26 -0700
Re: Java puzzler Tom Anderson <twic@urchin.earth.li> - 2011-05-14 10:18 +0100
Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-14 08:09 -0700
Re: Java puzzler Lew <noone@lewscanon.com> - 2011-05-14 13:00 -0400
Re: Java puzzler Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-05-14 15:08 -0400
Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-14 13:25 -0700
Re: Java puzzler markspace <-@.> - 2011-05-14 08:46 -0700
Re: Java puzzler Spock <spock@starfleet.ufp> - 2011-05-14 19:33 -0400
Re: Java puzzler Tom Anderson <twic@urchin.earth.li> - 2011-05-15 00:41 +0100
Re: Java puzzler markspace <-@.> - 2011-05-14 18:35 -0700
Re: Java puzzler Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-05-14 23:43 -0400
Re: Java puzzler Tom Anderson <twic@urchin.earth.li> - 2011-05-15 11:16 +0100
Re: Java puzzler markspace <-@.> - 2011-05-15 05:40 -0700
Re: Java puzzler Tom Anderson <twic@urchin.earth.li> - 2011-05-15 15:23 +0100
Re: Java puzzler markspace <-@.> - 2011-05-15 08:09 -0700
Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-15 07:37 -0700
Re: Java puzzler markspace <-@.> - 2011-05-15 08:00 -0700
Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-15 08:16 -0700
Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-15 07:35 -0700
Re: Java puzzler markspace <-@.> - 2011-05-15 08:11 -0700
Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-15 08:15 -0700
Re: Java puzzler Lew <noone@lewscanon.com> - 2011-05-15 13:11 -0400
Re: Java puzzler Nancy 3 <n3@gmai1.c0m> - 2011-05-12 20:47 -0400
Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-12 18:00 -0700
Re: Java puzzler markspace <-@.> - 2011-05-12 18:01 -0700
Re: Java puzzler Nancy 3 <n3@gmai1.c0m> - 2011-05-12 21:22 -0400
Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-12 18:32 -0700
Re: Java puzzler Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-05-12 22:34 -0400
Re: Java puzzler Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-05-12 22:27 -0400
Re: Java puzzler "John B. Matthews" <nospam@nospam.invalid> - 2011-05-12 00:28 -0400
Re: Java puzzler Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-05-12 10:33 -0400
Re: Java puzzler Lew <noone@lewscanon.com> - 2011-05-11 09:12 -0400
Re: Java puzzler Lew <noone@lewscanon.com> - 2011-05-11 09:13 -0400
Re: Java puzzler markspace <-@.> - 2011-05-11 08:00 -0700
csiph-web