title: Performance vs Readability with optional parameter
body: <p>Suppose that I have to call same method for each member of a vector contained in a class.<br>
  If element-i of the vector has a certain value, I have to modify it.<br>
  I've <strong>max 10</strong> element in this vector.</p>
  
  <p>What is the best way to do?<br>
  - Call a method with an optional parameter?<br>
  - Or call a method with an if-else statment inside?</p>
  
  <pre><code>class A {   
    public:    
     A();   
     void doSomething(const string&amp; s) {   
        if(s=="foo") {  
          std::cout &lt;&lt; s;   
        } else {   
          std::cout &lt;&lt; s &lt;&lt; ".dat"   
        }   
      }    
      void doSomethingDef(const string&amp; s, const string&amp; v = "")  {   
        std::cout &lt;&lt; s &lt;&lt; v;   
      }      
    private:   
      std::vector&lt;std::string&gt; list_;      
  }  
  
  int main() {   
    A a;  
  }  
  
  
  /* Constructor with method 1 */   
  A::A() {    
   std::vector&lt;std::string&gt;::iterator i = list_.begin();     
   for(; i != list_.end(); ++i) {    
     this-&gt;doSomething(*i);    
   }     
  }   
  
  /* Constructor with method 2 */   
  A::A() {    
     this-&gt;doSomethingDef(list[0]);   
     this-&gt;doSomethingDef(list[1]);   
     this-&gt;doSomethingDef(list[2]);  
     this-&gt;doSomethingDef(list[3]);    
     this-&gt;doSomethingDef(list[4], ".dat");  
     this-&gt;doSomethingDef(list[5], ".dat");  
     this-&gt;doSomethingDef(list[6]);  
     this-&gt;doSomethingDef(list[7]);  
     this-&gt;doSomethingDef(list[8]);  
     this-&gt;doSomethingDef(list[9]);  
  }   
  </code></pre>