title: Is it a best practice to use unsigned data types to enforce non-negative and/or valid values?
body: <p>Recently, during a refactoring session, I was looking over some code I wrote and noticed several things:</p>
  
  <ol>
  <li>I had functions that used <code>unsigned char</code> to enforce values in the interval [0-255].</li>
  <li>Other functions used <code>int</code> or <code>long</code> data types with <code>if</code> statements inside the functions to <em>silently</em> clamp the values to valid ranges.</li>
  <li>Values contained in classes and/or declared as arguments to functions that had an unknown <code>upper bound</code> but a known and definite non-negative <code>lower bound</code> were declared as an <code>unsigned</code> data type (<code>int</code> or <code>long</code> depending on the <em>possibility</em> that the <code>upper bound</code> went above 4,000,000,000).</li>
  </ol>
  
  <p>The inconsistency is unnerving. Is this a good practice that I should continue? Should I rethink the logic and stick to using <code>int</code> or <code>long</code> with appropriate non-notifying clamping?</p>
  
  <p>A note on the use of "appropriate": There are cases where I use <code>signed</code> data types and throw notifying exceptions when the values go out of range but these are reserved for <code>divde by zero</code> and <code>constructors</code>.</p>