Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ "Named Parameter Idiom" vs. Boost::Parameter library

I've looked at both the Named Parameter Idiom and the Boost::Parameter library. What advantages does each one have over the other? Is there a good reason to always choose one over the other, or might each of them be better than the other in some situations (and if so, what situations)?

like image 237
Head Geek Avatar asked Oct 15 '08 03:10

Head Geek


3 Answers

Implementing the Named Parameter Idiom is really easy, almost about as easy as using Boost::Parameter, so it kind of boils down to one main point.

-Do you already have boost dependencies? If you don't, Boost::parameter isn't special enough to merit adding the dependency.

Personally I've never seen Boost::parameter in production code, 100% of the time its been a custom implementation of Named Parameters, but that's not necessarily a good thing.

like image 95
Robert Gould Avatar answered Oct 12 '22 13:10

Robert Gould


Normally, I'm a big fan of Boost, but I wouldn't use the Boost.Parameter library for a couple of reasons:

  1. If you don't know what's going on, the call looks like you're assigning a value to a variable in the scope on the calling function before making the call. That can be very confusing.
  2. There is too much boilerplate code necessary to set it up in the first place.
like image 42
Ferruccio Avatar answered Oct 12 '22 13:10

Ferruccio


Another point, while I have never used Named Parameter Idiom, I have used Boost Parameter for defining up to 20 optional arguments. And, my compile times are insane. What used to take a couple seconds, now takes 30sec. This adds up if you have a library of stuff that use your one little application that you wrote using boost parameter. Of course, I might be implementing it wrongly, but I hope this changes, because other than that, i really like it.

like image 39
sdf Avatar answered Oct 12 '22 14:10

sdf