James Gosling Explains Why Java Byte Is Signed

Initially, I was surprised that Java decides to indicate that byte signed, with a range of -128..127 (inclusive). I got the impression that most representations with 8-bit unsigned numbers with a range of 0..255 instead (for example, IPv4 in decimal ).

So James Gosling was asked to explain why he decided that byte signed? Were there any known discussions / discussions on this subject between authoritative developers of the programming language and / or critics?

+46
java types language-design byte
Jun 24 '10 at 8:27
source share
4 answers

Simplicity seemed to be the main reason. From this interview :

Gosling: for me, as a developer of a language that I really don't consider myself these days, what β€œsimple” really ultimately meant, I could expect J. Random Developer to put the specification into his head. This definition says that, for example, Java is not - and in fact many of these languages ​​have many angular cases that no one understands. Try any C developer about unsigned, and pretty soon you will find that almost no C developer understands what happens with unsigned, which means unsigned arithmetic. Such things have made it difficult. The language part of Java, I think, is quite simple. Libraries you need to find.

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

+25
Jun 24 '10 at 8:32
source share

According to the "Oak Language Specification 0.2", aka Java:

"The byte oak type is what C programmers use to denote the char type. But in Oak, characters are 16 bits wide. Having a separate byte type eliminates the confusion in C between interpreting char as an 8-bit integer and as a character."

You can get a copy of the postscript from here:

http://cretesoft.com/archive/files/OakSpec0.2.ps ( partial copy on scribd )

There is also part of an interview posted on this site: (Where does he protect the absence of an unsigned byte in java)

http://www.darksleep.com/player/JavaAndUnsignedTypes.html

Adding an interview taken from the above page ...

* " http://www.gotw.ca/publications/c_family_interview.htm

Q: Programmers often talk about the pros and cons of programming in "plain language." What does this phrase mean for you is [C / C ++ / Java] a simple language in your view?

Richie: [deleted for brevity]

Stroustrup: [deleted for brevity]

Gosling: for me, as a language designer, which I really don’t think like today, that the β€œsimple” really turned out to be. I expect J. Random Developer to put the specification into his head. What the definition says is that, for example, Java is not - and in fact a lot of angular affairs end up in these languages ​​that no one really understands. Try any C developer about unsigned, and pretty soon you will find that almost no C developer understands what is unsigned, what unsigned arithmetic is. Complex C made such things. The language part of Java, I think, is quite simple. Libraries you need to find.

On the other hand .... According to http://www.artima.com/weblogs/viewpost.jsp?thread=7555

Once upon a tree ... Heinz Kabutz July 15, 2003

... Trying to fill in the gaps in the history of Java, I started digging through Sun, and eventually came across the oak language Specification for Oak Version 0.2. Oak was the original name for what is now widely known as Java, and this manual is the oldest manual available for Oak (i.e. Java) .... Unsigned integer values ​​(section 3.1)

The specification states: "Four integer types of width 8, 16, 32 and 64 bits, and are signed without prefix by an unsigned modifier.

On the sidebar it says: "unsigned has not yet been implemented, it may never be." How you were right. "*

+12
Jun 24 '10 at 8:45
source share

I don't know any direct quotes from James Gosling, but there is an official RFE for unsigned byte :

Error ID: 4186775: request unsigned integer types, especially. unsigned byte

Status : 11-closed, will not be fixed , request for improvement

Please extend your Java design to use unsigned types, in particular unsigned byte .

I was wondering why in Java there are no unsigned integer types. It seems to me that for byte -length values ​​it is extremely inconvenient not to have them [...]

I understand that this was a design decision by Java developers. I do not understand why. Did they consider unsigned whole types to be evil or harmful, and decided to protect me from themselves?

+5
Jun 24 '10 at 8:33
source share

There is no reason for the byte be unsigned. if you have a char type to represent characters, byte usually does not do this char job.

+1
Jun 24 2018-10-06T00:
source share



All Articles