title: If you have to use an accessor function two times in a block of code,
body: <p>I have a question. Suppose you have to call a function twice in a block of code, and are guaranteed for it to return the same value both times. Should you optimize your code by creating an extra variable?</p>
  
  <p>Example: </p>
  
  <p>Should</p>
  
  <pre><code>foo1(v.length()); // foo1 doesn't modify v.length()
  foo2(v.length());
  </code></pre>
  
  <p>be changed to </p>
  
  <pre><code>int vlen = v.length();
  foo1(vlen);
  foo2(vlen);
  </code></pre>
  
  <p>for optimability? </p>