Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
527 views
in Technique[技术] by (71.8m points)

types - James Gosling's explanation of why Java's byte is signed

I was initially surprised that Java decides to specify that byte is signed, with a range from -128..127 (inclusive). I'm under the impression that most 8-bit number representations are unsigned, with a range of 0..255 instead (e.g. IPv4 in dot-decimal notation).

So has James Gosling ever been asked to explain why he decided that byte is signed? Has there been notable discussions/debates about this issue in the past between authoritative programming language designers and/or critics?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It appears that simplicity was the main reason. From this interview:

Gosling: 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. The language part of Java is, I think, pretty simple. The libraries you have to look up.

My initial assumption was that it's because Java doesn't have unsigned numeric types at all. Why should byte be an exception? char is a special case because it has to represent UTF-16 code units (thanks to Jon Skeet for the quote)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...