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

  • Home
  • SEARCH
  • 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 6349939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:42:52+00:00 2026-05-24T21:42:52+00:00

In order to keep the main() (in c++) as clean/small as possible, there a

  • 0

In order to keep the main() (in c++) as clean/small as possible, there a a few options you can choose but which of them is best? initialize all variables in main, init them outside of main as global, global in .h, init them in main BUT set there values elsewhere (by passing them over to a function). there may be other ways but, what is the BEST way to keep the main() as clean/clear/small as possible?

  • 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-24T21:42:54+00:00Added an answer on May 24, 2026 at 9:42 pm

    There are some common patterns, like encapsulating data and operations in classes that make sense. For example, if you process command line arguments or configuration from files, you can create a Config class that you initialize from argc and argv and/or possibly a file, and then use that as storage for the user controllable parameters.

    Another common pattern is moving all of main into a class, that contains the state as member attributes and has a run (or main call it as you wish) member function. This allows for an easy refactor of main where you do not have to pass all of the state as function arguments. Sometimes those two options are mixed and the class initializes from the arguments of main.

    There is no clear answer, as it depends on what your main is currently doing, in some cases it still can make sense to keep a long-ish main if the different parts are clearly separated and it is not too long, where long-ish and long are subjective measures…

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

Sidebar

Related Questions

in order to keep as few SQL statements as possible, I want to do
I have a C program which uses Lua for scripting. In order to keep
What coding tricks, compilation flags, software-architecture considerations can be applied in order to keep
In order to keep my code clean and organized, I split my classes up
Someone told me to do this in order to keep track of latest people
Why is it necessary to keep visited flag for iterative post order traversal and
In order to keep my Qt project somewhat organized (using Qt Creator), I've got
In PHP an Associative Array keeps its order. // this will keep its order
I am working on a cocoa software and in order to keep the GUI
I would like to create my logout view for many reasons but the main

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.