Let’s take a for
loop for example:
medals := []string{"gold", "silver", "bronze"}
for i := len(medals) - 1; i >= 0; i-- {
fmt.Println(medals[i]) // "bronze", "silver", "gold"
}
If we used an unsigned int in this scenario, after the third item the value of i
will be the maximum uint value (like $2^{64} - 1$), and the program will attempt to access an element outside the bounds of the slice - which would fail at run time, or panic.
For this reason, unsigned numbers tend to be used only when their bitwise operators or peculiar arithmetic operators are required, as when implementing bit sets, parsing binary file formats, or for hashing and cryptography. They are typically not used for merely non-negative quantities.
An excerpt from The Go Programming Language Book by Alan A. A. Donovan and Brian W. Kernighan.