A
asit
Why java does not have an unsigned data type ????
asit said:Why java does not have an unsigned data type ????
Given that all computations involving bytes are performed on int's,Eric said:But it does! With a range of '\u0000' through '\uffff' ...
As for the other possibilities, I don't know. Perhaps the
inventors thought it would be a needless complication. Or that
a keyword beginning "un" sounded too negative.
Speaking for myself, the only place I really regret their
decision is with `byte', which would be far more useful (to me,
anyhow) if its range were 0 through 255.
The unsigned types in C have been the cause of many bugs, particularly
when mixed with signed types (rather unexpectedly the signed types get
converted to unsigned). It would have been more sensible if the unsigned
types were promoted to signed values of the next larger size (where
possible). However had Java done this, there would have been endless
confusion with mistranslated C code. So the only practical alternative
to C's broken approach was to leave the unsigned types out.
asit said:Why java does not have an unsigned data type ????
Mark said:Given that all computations involving bytes are performed on int's,
there isn't much lost here. Lack of unsigned int is a bit more of a
nuisance as you have to go to a larger type (although if you are using a
64 bit machine that may not have performance implications either).
Eric said:Speaking for myself, the only place I really regret their
decision is with `byte', which would be far more useful (to me,
anyhow) if its range were 0 through 255.
Eric said:Tom said:[...]
That's certainly what James Gosling says:
"For me as a language designer, which I don't really count myself as
these days, what "simple" really ended up meaning was could I expect
J. Random Developer to hold the spec in his head. That definition says
that, for instance, Java isn't -- and in fact a lot of these languages
end up with a lot of corner cases, things that nobody really
understands. Quiz any C developer about unsigned, and pretty soon you
discover that almost no C developers actually understand what goes on
with unsigned, what unsigned arithmetic is. Things like that made C
complex." [1]
Brave words for someone who can't even form a grammatically
meaningful sentence in English. Go ahead: Try to parse the second
sentence of this, this, utterance. The only intelligible piece of
it is "Java isn't," something Redmond might desire but is contrary
to fact.
As for the "corner cases, things that nobody really
understands" -- well, I've got a use of generics that NetBeans
flags as an error but javac accepts without complaint. Which
of them "really understands" Java?
Eric said:Speaking (again) for myself, I find that nearly every time
I use a `byte' I have to write `b & 0xFF' to make it work.
see http://mindprod.com/jgloss/unsigned.htmlWhy java does not have an unsigned data type ????
Eric said:That last line looks like a thinko; I imagine you meant
short s = (short)((hi << 8) | (lo & 0xFF));
Choosing an int type a size bigger is not always suitable for a give
context and not possible for long.
Tom said:[...]
That's certainly what James Gosling says:
"For me as a language designer, which I don't really count myself as these
days, what "simple" really ended up meaning was could I expect J. Random
Developer to hold the spec in his head. That definition says that, for
instance, Java isn't -- and in fact a lot of these languages end up with a
lot of corner cases, things that nobody really understands. Quiz any C
developer about unsigned, and pretty soon you discover that almost no C
developers actually understand what goes on with unsigned, what unsigned
arithmetic is. Things like that made C complex." [1]
Brave words for someone who can't even form a grammatically
meaningful sentence in English. Go ahead: Try to parse the second
sentence of this, this, utterance. The only intelligible piece of
it is "Java isn't," something Redmond might desire but is contrary
to fact.
As for the "corner cases, things that nobody really understands" --
well, I've got a use of generics that NetBeans flags as an error but
javac accepts without complaint. Which of them "really understands"
Java?
Arne Vajhøj said:C# got that one right !
Mike said:I deliberately got it wrong to show how treacherous signed bytes are.
Mike said:I suspect that if it were possible for Sun to revisit the decision, they'd
get it right too.
Tom said:BigInteger!
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.