Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2006-09-26 17:08:29

Oleg Abrosimov <beholder_at_[hidden]> writes:

> Hello David,
> As a result of this discussion I've read boost::parameter docs
> completely. And now I want to apologize for my aggressive post. This
> library is very sophisticated.
> Nevertheless, I didn't become it's proponent and there are some thoughts
> about the overall function parameters problem that can be useful for
> this discussion:
> 1) parameter's type is not a panacea
> It means that giving function parameters unique types can solve the
> problem of mistakenly swapping them, but is not always applicable,
> sometimes impractical,

If you're referring to deduced parameters
(, of course it's
not a panacea. That's why the library supports named parameters.

> doesn't solve problem with optional parameters, etc.

I don't know what problem you're referring to, but deduced parameters,
where applicable, certainly do solve the main problem with optional
parameters (spurious order dependencies).

> 2) many parameters:
> - some are mandatory and
> - some are optional with default values supplied
> It means that both optional and required parameters should be taken into
> account.

Both optional and required parameters are taken into account by the
Parameter library. What documentation did you read that made you
think they weren't?

> Definition:
> configuration - is a set of parameters for a given function
> f1(configuration);
> Requirements for ideal solution of implementing and using function's
> configurations:
> 1) simple implementation of configuration and function that uses it
> 2) maximum maintainability
> it means:
> a) configuration parameters should be specified as close to
> function call as possible
> b) configuration parameters should be visible (names)
> c) configuration reuse
> solutions:
> 1) positional function parameters
> + mandatory parameters
> + optional parameters
> - invisible parameters


> - interference of optional parameters complicates its usage
> - reuse is not possible
> + no ambiguity with other language constructs
> + implementation is simple
> 2) named parameters
> + mandatory parameters
> + optional parameters
> + visible parameters
> - reuse is not possible (it is not _very_ important, but important. Is
> there a way to extend parameter lib to support such a reuse?)

You're not saying what you mean by "reuse." We think reuse is very
possible with the Parameter library, so it's quite unclear what you
might be referring to.

> - ambiguity with other language constructs
> (it is very important drawback. As I realized from parameter docs,

You're not being specific enough here either. I can't imagine what
ambiguity you mean.

> great effort should be made to make such an ambiguity possible. It would
> be better IMO to eliminate this efforts in implementation and the
> ambiguity in one shot - provide special may be auxiliary structure -
> like syntax to use parameters)

It's unclear what you mean.

> - implementation is not simple
> (really. all this nightmare can be done for library that is created
> once and used many times, but I need a tool that can be used on a daily
> basis for ordinary code.

One can use Boost.Parameter for ordinary code on a daily basis. We
(Boost Consulting) have done it for our major customers and they are
*very* satisfied with the results.

> it means that simplicity of an implementation
> should be very close to the solution with auxiliary structures below)

IMO the implementation complexity doesn't matter as long as it works
and gives comprehensible feedback when misused. Do you inspect the
source code of your compiler and complain about its implementation

> 3) auxiliary structures
> - mandatory parameters
> + optional parameters
> + visible parameters
> + reuse is possible
> + no ambiguity with other language constructs
> + implementation is simple
> The last approach with auxiliary structures has only one drawback - it
> is not possible to have required parameters with it. May be you, David,
> can see a way how parameter lib can be reused/extended into something
> like the las solution, but with all '+' marks?

No, and it has more drawbacks. Go back and read the Parameter library
review commentary if you want to find all of them.

> ( I remember additional arguments by Michael Walter:
> a) parameter values are copied
> b) parameter values need to be default-constructable (into a valid state)
> but they are not important for me just now
> )

Well, those are two of the drawbacks, and they count (maybe not for
you, but they do count).

> May be the best solution that we can have now is:
> //implementation:
> BOOST_DECLARE_PARAM_OPTIONAL(type1, name1, def_val1)
> BOOST_DECLARE_PARAM_OPTIONAL(type3, name3, def_val3)
> BOOST_DECLARE_PARAM_OPTIONAL(type4, name4, def_val4)

That's not a nightmare?

> void func(TFuncParams const& params)
> {
> cout << params.name1;
> // etc.
> }
> usage:
> BOOST_PARAM_OPTIONAL(params, name1, val1)
> BOOST_PARAM_REQIRED(params, name2, val2)
> func(params);
> The idea is that all boost::parameter magic is hidden by those macroses.
> The question is - can it be really done?

I don't know. The above meets few if any of my requirements for such
a library, so determining feasibility will have to fall to someone else.

Dave Abrahams
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at