title: Unnecessary curly braces in C++
body: <p>When doing a code review for a colleague today I saw a peculiar thing. He had surrounded his new code with curly braces like this:</p>
  <pre><code>Constructor::Constructor()
  {
     // Existing code
  
     {
        // New code: do some new fancy stuff here
     }
  
     // Existing code
  }
  </code></pre>
  <p>What is the outcome, if any, from this? What could be the reason for doing this? Where does this habit come from?</p>
  <p>The environment is embedded devices. There is a lot of legacy C code wrapped in C++ clothing. There are a lot of C turned C++ developers.</p>
  <p>There are no critical sections in this part of the code. I have only seen it in this part of the code. There are no major memory allocations done, just some flags that are set, and some bit twiddling.</p>
  <p>The code that is surrounded by curly braces is something like:</p>
  <pre><code>{
     bool isInit;
     (void)isStillInInitMode(&amp;isInit);
     if (isInit) {
       return isInit;
     }
  }
  </code></pre>
  <p>(Don't mind the code, just stick to the curly braces... ;) )
  After the curly braces there are some more bit twiddling, state checking, and basic signaling.</p>
  <p>I talked to the guy and his motivation was to limit the scope of variables, naming clashes, and some other that I couldn't really pick up.</p>
  <p>From my point of view this seems rather strange and I don't think that the curly braces should be in our code. I saw some good examples in all the answers on why one could surround code with curly braces, but shouldn't you separate the code into methods instead?</p>
  <pre class="lang-none prettyprint-override"><code>fsdf
  </code></pre>