title: What should be the approach to avoid duplicate code in below pseudo c code snippet?
body: <pre><code>if(var == something) {
      A();
      B();
  } else if(var == something_else) {
      A();
      B();
      C();
  } else {
      assert(false);
  }
  </code></pre>
  
  <p>How can i avoid duplicate code of calling A() and B() in both <code>if</code> cases. Should i use switch case like,</p>
  
  <pre><code>switch(var) {
  case something:
  case something_else:
      A();
      B();
      break;
  }
  if (var == something_else)
     C():
  </code></pre>
  
  <p>What is the better solution? Is there any performance penalty in <code>switch</code> vs <code>if else</code>?</p>