Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7665839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:40:45+00:00 2026-05-31T14:40:45+00:00

When doing a code review for a colleague today I saw a peculiar thing.

  • 0

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:

Constructor::Constructor()
{
   // Existing code

   {
      // New code: do some new fancy stuff here
   }

   // Existing code
}

What is the outcome, if any, from this? What could be the reason for doing this? Where does this habit come from?

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.

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.

The code that is surrounded by curly braces is something like:

{
   bool isInit;
   (void)isStillInInitMode(&isInit);
   if (isInit) {
     return isInit;
   }
}

(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.

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.

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?

fsdf
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:40:47+00:00Added an answer on May 31, 2026 at 2:40 pm

    It’s sometimes nice since it gives you a new scope, where you can more "cleanly" declare new (automatic) variables.

    In C++ this is maybe not so important since you can introduce new variables anywhere, but perhaps the habit is from C, where you could not do this until C99. 🙂

    Since C++ has destructors, it can also be handy to have resources (files, mutexes, or whatever) automatically released as the scope exits, which can make things cleaner. This means you can hold on to some shared resource for a shorter duration than you would if you grabbed it at the start of the method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been doing code review (mostly using tools like FindBugs) of one of our
I was doing a code review and I saw assignment of single quoted strings
I was doing some code review today and came across an old code written
I'm doing code review and came across a class that uses all static methods.
I am currently doing a code review and the following code made me jump.
Context PHP 5.3.x Overview After doing a code-review with an associate who uses both
I use Environment.NewLine, my colleagues use vbCrLf. When I'm doing a code review for
Was just doing a code review and started to wonder: I thought if (self
Doing a code review I've stumbled over GWM in Java-Spring-GWT web-application. As this product
I am doing a code review with a client. It is a proc on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.