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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:40:33+00:00 2026-05-25T20:40:33+00:00

Most of the applications we developers write need to be externally parametrized at startup.

  • 0

Most of the applications we developers write need to be externally parametrized at startup. We pass file paths, pipe names, TCP/IP addresses etc. So far I’ve been using command line to pass these to the appplication being launched. I had to parse the command line in main and direct the arguments to where they’re needed, which is of course a good design, but is hard to maintain for a large number of arguments. Recently I’ve decided to use the environment variables mechanism. They are global and accessible from anywhere, which is less elegant from architectural point of view, but limits the amount of code.

These are my first (and possibly quite shallow) impressions on both strategies but I’d like to hear opinions of more experienced developers — What are the ups and downs of using environment variables and command line arguments to pass arguments to a process? I’d like to take into account the following matters:

  1. design quality (flexibility/maintainability),
  2. memory constraints,
  3. solution portability.

Remarks:

Ad. 1. This is the main aspect I’m interested in.

Ad. 2. This is a bit pragmatic. I know of some limitations on Windows which are currently huge (over 32kB for both command line and environment block). I guess this is not an issue though, since you just should use a file to pass tons of arguments if you need.

Ad. 3. I know almost nothing of Unix so I’m not sure whether both strategies are as similarily usable as on Windows. Elaborate on this if you please.

  • 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-25T20:40:33+00:00Added an answer on May 25, 2026 at 8:40 pm

    1) I would recommend avoiding environmental variables as much as possible.

    Pros of environmental variables

    • easy to use because they’re visible from anywhere. If lots of independent programs need a piece of information, this approach is a whole lot more convenient.

    Cons of environmental variables

    • hard to use correctly because they’re visible (delete-able, set-able) from anywhere. If I install a new program that relies on environmental variables, are they going to stomp on my existing ones? Did I inadvertently screw up my environmental variables when I was monkeying around yesterday?

    My opinion

    • use command-line arguments for those arguments which are most likely to be different for each individual invocation of the program (i.e. n for a program which calculates n!)
    • use config files for arguments which a user might reasonably want to change, but not very often (i.e. display size when the window pops up)
    • use environmental variables sparingly — preferably only for arguments which are expected not to change (i.e. the location of the Python interpreter)
    • your point They are global and accessible from anywhere, which is less elegant from architectural point of view, but limits the amount of code reminds me of justifications for the use of global variables 😉

    My scars from experiencing first-hand the horrors of environmental variable overuse

    • two programs we need at work, which can’t run on the same computer at the same time due to environmental clashes
    • multiple versions of programs with the same name but different bugs — brought an entire workshop to its knees for hours because the location of the program was pulled from the environment, and was (silently, subtly) wrong.

    2) Limits

    If I were pushing the limits of either what the command line can hold, or what the environment can handle, I would refactor immediately.

    I’ve used JSON in the past for a command-line application which needed a lot of parameters. It was very convenient to be able to use dictionaries and lists, along with strings and numbers. The application only took a couple of command line args, one of which was the location of the JSON file.

    Advantages of this approach

    • didn’t have to write a lot of (painful) code to interact with a CLI library — it can be a pain to get many of the common libraries to enforce complicated constraints (by ‘complicated’ I mean more complex than checking for a specific key or alternation between a set of keys)
    • don’t have to worry about the CLI libraries requirements for order of arguments — just use a JSON object!
    • easy to represent complicated data (answering What won't fit into command line parameters?) such as lists
    • easy to use the data from other applications — both to create and to parse programmatically
    • easy to accommodate future extensions

    Note: I want to distinguish this from the .config-file approach — this is not for storing user configuration. Maybe I should call this the ‘command-line parameter-file’ approach, because I use it for a program that needs lots of values that don’t fit well on the command line.


    3) Solution portability: I don’t know a whole lot about the differences between Mac, PC, and Linux with regard to environmental variables and command line arguments, but I can tell you:

    • all three have support for environmental variables
    • they all support command line arguments

    Yes, I know — it wasn’t very helpful. I’m sorry. But the key point is that you can expect a reasonable solution to be portable, although you would definitely want to verify this for your programs (for example, are command line args case sensitive on any platforms? on all platforms? I don’t know).


    One last point:

    As Tomasz mentioned, it shouldn’t matter to most of the application where the parameters came from.

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

Sidebar

Related Questions

Should developers be limited to certain applications for development use? For most, the answer
Most applications created with Microsoft developer tools need some kind of runtime to be
Most web applications have a Location field, in which uses may enter a Location
Most web applications depend on some kind of session with the user (for instance,
Historically I've been completely against using ORMS for all but the most basics applications.
I tend to use a StatusStrip at the bottom of most of my applications
I have an application that is database intensive. Most of the applications methods are
How do most people handle updating ASP.NET applications running in a webfarm? I am
When writing multi-threaded applications, one of the most common problems experienced are deadlocks. My
When writing multithreaded applications, one of the most common problems experienced is race conditions.

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.