io - The number of bytes read and unsigned numbers -
as example clarify question, in google go 1.0, following interface defined in "io" package:
type reader interface { read(p []byte) (n int, err error) } especially result parameter list (n int, err error) intrigues me. intrinsically number of bytes can not negative, according documentation of interface:
it returns number of bytes read (0 <= n <= len(p))[...]
in c reason use int in-band value -1 signal error condition (see effective go: multiple return values). because of multiple return values, special in-band values not necessary.
there exists type uint in go 1.0.
what specific reason using int versus uint in case of values use positive range [0,∞) without need having special in-band values?
the de facto numeric type integers in cases int. example, len(x) , cap(x) return int values though cannot negative. in cases returning int helps avoid type conversions between different numeric types.
so yes, read() have returned uint, make more unwieldy work with.
Comments
Post a Comment