title: Why does len() returned a signed value?
body: <p>Go's builtin <a href="https://golang.org/pkg/builtin/#len" rel="noreferrer"><code>len()</code> function</a> returns a signed <code>int</code>. Why wasn't a <code>uint</code> used instead?</p>
  
  <p>Is it ever possible for <code>len()</code> to return something negative?<br>
  As far as I can tell, the answer is no:</p>
  
  <ul>
  <li><a href="https://golang.org/ref/spec#Array_types" rel="noreferrer">Arrays</a>: "The number of elements is called the length and is never negative."</li>
  <li><a href="https://golang.org/ref/spec#Length_and_capacity" rel="noreferrer">Slices</a>: "At any time the following relationship holds: <code>0 &lt;= len(s) &lt;= cap(s)</code>"</li>
  <li><a href="https://golang.org/ref/spec#Map_types" rel="noreferrer">Maps</a> "The number of map elements is called its length". (I couldn't find anything in the spec that explicitly restricts this to a nonnegative value, but it's difficult for me to understand how there could be fewer than 0 elements in a map)</li>
  <li><a href="https://golang.org/ref/spec#String_types" rel="noreferrer">Strings</a> "A string value is a (possibly empty) sequence of bytes.... The length of a string s (its size in bytes) can be discovered using the built-in function <code>len()</code>" (Again, hard to see how a sequence could have a negative number of bytes)</li>
  <li><a href="https://golang.org/ref/spec#Length_and_capacity" rel="noreferrer">Channels</a> "number of elements queued in channel buffer (ditto)</li>
  </ul>