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 48359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:16:03+00:00 2026-05-10T16:16:03+00:00

What guidelines do you follow to improve the general quality of your code? Many

  • 0

What guidelines do you follow to improve the general quality of your code? Many people have rules about how to write C++ code that (supposedly) make it harder to make mistakes. I’ve seen people insist that every if statement is followed by a brace block ({...}).

I’m interested in what guidelines other people follow, and the reasons behind them. I’m also interested in guidelines that you think are rubbish, but are commonly held. Can anyone suggest a few?

To get the ball rolling, I’ll mention a few to start with:

  • Always use braces after every if / else statement (mentioned above). The rationale behind this is that it’s not always easy to tell if a single statement is actually one statement, or a preprocessor macro that expands to more than one statement, so this code would break:
     // top of file:     #define statement doSomething(); doSomethingElse      // in implementation:     if (somecondition)         doSomething(); 

but if you use braces then it will work as expected.

  • Use preprocessor macros for conditional compilation ONLY. preprocessor macros can cause all sorts of hell, since they don’t allow C++ scoping rules. I’ve run aground many times due to preprocessor macros with common names in header files. If you’re not careful you can cause all sorts of havoc!

Now over to you.

  • 1 1 Answer
  • 2 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. 2026-05-10T16:16:04+00:00Added an answer on May 10, 2026 at 4:16 pm

    A few of my personal favorites:

    Strive to write code that is const correct. You will enlist the compiler to help weed out easy to fix but sometimes painful bugs. Your code will also tell a story of what you had in mind at the time you wrote it — valuable for newcomers or maintainers once you’re gone.

    Get out of the memory management business. Learn to use smart pointers: std::auto_ptr, std::tr1::shared_ptr (or boost::shared_ptr) and boost::scoped_ptr. Learn the differences between them and when to use one vs. another.

    You’re probably going to be using the Standard Template Library. Read the Josuttis book. Don’t just stop after the first few chapters on containers thinking that you know the STL. Push through to the good stuff: algorithms and function objects.

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

Sidebar

Related Questions

I ask my developers who write C# code to follow StyleCop's guidelines. It's great
Are there any guidelines to writing Google App Engine Python code that would work
My web applications have pages that display many static fields. I know that poor
I have been trying to follow StyleCop's guidelines on a project, to see if
I have recently encountered an issue that is related to code running in the
I fully realize that what I am proposing does not follow the .NET guidelines,
Are there standard/common guidelines for CSS that you should always follow? For example something
I have been trying to follow the guidelines in this Microsoft article to authenticate
Here http://source.android.com/source/code-style.html#follow-field-naming-conventions it is stated that : Field Names Non-public, non-static field names start
What general guidelines should I follow to degrade a JS-based web application gracefully? Are

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.