Subject: Re: [boost] [local] Review
From: Joel de Guzman (joel_at_[hidden])
Date: 2011-11-21 01:41:09
> On Nov 21, 2011, at 2:16 PM, Thomas Heller wrote:
>> ... I tried to distance myself from comparing Boost.Local to Bind, Lambda and
>> Phoenix, because the comparison just isn't fair. I try to see them as an alternative
>> to regular functions. And, TBH, it just doesn't cut it. Mainly because of the macro
>> overhead introduced.
On 11/21/2011 1:27 PM, Gregory Crosswhite wrote:
> Yes, but the macro overhead buys you the ability to put the code where it is being
> used, and to avoid writing what is effectively the same code multiple times. To see
> one example of why this is an advantage, suppose that you need to bind another variable
> in your callback. With plain functions, you would need to scroll outside of your
> function to where you defined the callback function, add a parameter to that function,
> and then jump back to where it was being bound using Boost.Bind and then add the
> variable to the proper position. By contrast, with Boost.Local you don't have to jump
> around your code and you don't have to write multiple lines of code that essentially
> say the same thing, you can just add a single line to the callback macro --- which,
> again, is conveniently located *right* where it is being used so that you don't need to
> go far --- and you are done.
1) You don't have to scroll up and down and jump around your code if you
avoid big function bodies --always a good practice anyway.
2) If you have lots of local functions, you'll still have to scroll
up and down and jump around your code. This happens when you refactor
big function bodies into N smaller functions where N is more than
a few. If N == 1 or 2, then 1) above applies.
> Also, since the type is detected by Boost.Local
> automatically, if you change the type of the bound variable yo u don't have to do
> anything at all, whereas with a plain function callback you would have to scroll up and
> update the type manually.
3) Make them templates.
-- Joel de Guzman http://www.boostpro.com http://boost-spirit.com