title: Are there any downsides to marking all variables you don't modify const?
body: <p>After much googling I've found a lot about marking functions and their parameters as <code>const</code>, but no guide on marking variables as <code>const</code>.</p>
  
  <p>Here's a really simple example:</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;iostream&gt;
  
  void example(const std::string&amp; x) {
    size_t length = x.length();
    for (size_t i = 0; i &lt; length; ++i) {
      std::cout &lt;&lt; x.at(i) &lt;&lt; std::endl;
    }
  }
  
  int main() {
    example("hello");
  }
  </code></pre>
  
  <p>Why not make </p>
  
  <pre><code>size_t length = x.length();
  </code></pre>
  
  <p>const like</p>
  
  <pre><code>const size_t length = x.length();
  </code></pre>
  
  <p>by convention?</p>
  
  <p>I know such a small, simple example really doesn't show any huge benefit to this, but it seems like it'd be helpful in a larger codebase where you might accidentally mutate a variable you shouldn't have mutated.</p>
  
  <p>Despite that benefit, I don't really see it used that much (in the C++ codebases I've seen) or mentioned nearly as much as making functions and their parameters <code>const</code>.</p>
  
  <p>Is there some downside to doing this other than having to type 5 extra characters? I haven't found much on the topic, and I don't want to shoot myself in the foot if it's a problem having so many consts.</p>