xunzhang / gflags

Automatically exported from code.google.com/p/gflags
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

suggestion: namespaces #34

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
If instead of prefixing flags with FLAGS_ the DEFINE_* would define them in 
the current namespace, user could give them more meaningful prefixes, 
e.g. on per subsystem basis. And while "inside" subsystem namespace we 
won't have to type the prefix.

This suggestion still isn't perfect (for example it might make it appear that 
user can create the same flag in different namespaces, like foo:quiet and 
bar::quiet, which is not true as both correspond to -quiet) but I just wanted 
to start the discussion to figure out what would be the best solution or 
may be to be convinced that the current solution is perfect :)

// something like (beware: pseudocode++)

namespace foo {
   DEFINE_bool(quiet, false, "shut up");
}
...
namespace foo {
   DECLARE_bool(quiet);
}

...

main() {
  if (!foo::quiet) {
    std::cout << "Hello, world!";
  }
}

...

namespace foo {
  void bar() {
    if (!quiet) {
      make_noise();
    }
  }
}

Original issue reported on code.google.com by femistofel@gmail.com on 18 Feb 2010 at 9:00

GoogleCodeExporter commented 9 years ago
I meant this as "enhancement" but haven't found how to mark it so

Original comment by femistofel@gmail.com on 18 Feb 2010 at 9:02

GoogleCodeExporter commented 9 years ago
We've thought about this before but run into the same problem you mention: how 
do you 
handle the namespaces when specifying flags on the commandline?

The conclusion we came to is that commandline flags are, by nature, a global 
construct, and we should just work within that in the design rather than fight 
against 
it by trying to add a namespace system on top.

Original comment by csilv...@gmail.com on 18 Feb 2010 at 9:57