1 /** @page rationale Rationale
3 @section code_size Focus on code size
5 The program options library has two important properties:
6 - runtime performance is not important. After all, command line processing
7 is done only once, and the amount of data is small.
8 - code size matters. Since parsing command line is utility task, users
9 won't be glad to have lots of code linked to every binary which has
12 For the above reasons, the the library is designed so that it can be easily
13 used as shared library, with minimum code on the side of main application.
14 In particular, templates are used only where necessary, for example for
15 validation of user-defined types. In other places, boost::function is
16 used to allow customization, but keep templates out of the public
19 @section string_vs_enums Strings vs. enums
21 In some places, the library uses strings to convey information that
22 could be represented by enumerations or values. For example,
23 the program_options::option_description class allows to add "?" to the
24 parameter name to specify that the parameter is optional. For another
25 example, while program_options::cmdline class allows to obtain the
26 index of option, it does not require to specify an index for each option,
27 and it's possible to tell options by their names.
29 Such interface appears to be much more usable. If we were using
30 enumeration for different properties of parameter, there would be
31 another argument to many functions, the need to type long, possible
32 qualified names, and little advantage.
34 That little advantage is that if you type a wrong enumeration name,
35 you'd get a compile error. If you type '!' instead of '?' after parameter
36 name, you'd get incorrect behaviour. However, such errors are deemed
39 @section char_vs_string const char* vs. std::string
41 Most of the interface uses const char* where std::string seems a natural
42 choice. The reason is that those functions are called many times: for
43 example to declare all options. They are typically called with string
44 literals, and implicit conversion to string appears to take a lot of
45 code space. Providing both std::string and const char* version would
46 considerably bloat the interface. Since passing std::string is considered
47 rare, only const char* versions are provided.
49 @section init_syntax Initialization syntax
51 The syntax used for creating options_description instance was designed to
52 be as easy as possible in the most common case. Consider:
55 ("verbose", "", "verbosity level")
56 ("magic", "int", "magic value").notify(some_func)
59 Here, most common properties of options: name, presense of parameter and
60 description, are specified very concisely, and additional properties can
61 be given quite naturally, too.
63 Another possibility would be:
65 option_description d1(...), d2(...);
70 option_description d1(...), d2(...);
74 The drawback is the need to explicitly create new objects and give names
75 to them. The latter problem can be helped if objects are created inside
78 desc = option_description(...), option_description(...)
80 but there's still extra typing.
82 @section help_handling Handling of --help
84 It was suggested by Gennadiy Rozental that occurrence of <tt>--help</tt>
85 on command line results in throwing an exception. Actually, the
86 "special" option must have been configurable. This was not
87 implemented, because applications might reasonable want to process
88 the rest of command line even of <tt>--help</tt> was seen. For example,
89 <tt>--verbose</tt> option can control how much help should be output,
90 or there may be several subcommand with different help screens.