
Hello all, Boost.Local uses a special name `this_` to access the object `this` bound from the enclosing scope. Shall this name be `this_` or `_this` according to Boost practices? struct c { void g(int x) { ... } void f() { void BOOST_LOCAL_FUNCTION_PARAMS( (int x) (bind this) ) { this_->g(x); // <<<<<<<<< Shall this be `_this->g(x);` instead? ... } BOOST_LOCAL_FUNCTIO_NAME(l) ... } ... }; In particular, some library uses _ postfix for statements like mpl::if_ (not mpl::_if) while other uses _ prefix for variables like phoenix::local_names::_f (not local_names::f_). Thanks a lot. -- Lorenzo

AMDG On 04/03/2011 11:13 AM, Lorenzo Caminiti wrote:
Boost.Local uses a special name `this_` to access the object `this` bound from the enclosing scope. Shall this name be `this_` or `_this` according to Boost practices?
struct c { void g(int x) { ... } void f() { void BOOST_LOCAL_FUNCTION_PARAMS( (int x) (bind this) ) { this_->g(x); //<<<<<<<<< Shall this be `_this->g(x);` instead? ... } BOOST_LOCAL_FUNCTIO_NAME(l) ... } ... };
In particular, some library uses _ postfix for statements like mpl::if_ (not mpl::_if) while other uses _ prefix for variables like phoenix::local_names::_f (not local_names::f_).
The convention is that _xxx is used for placeholders. xxx_ is used when xxx is a keyword. In Christ, Steven Watanabe

On Sun, Apr 3, 2011 at 2:22 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
On 04/03/2011 11:13 AM, Lorenzo Caminiti wrote:
Boost.Local uses a special name `this_` to access the object `this` bound from the enclosing scope. Shall this name be `this_` or `_this` according to Boost practices?
struct c { void g(int x) { ... } void f() { void BOOST_LOCAL_FUNCTION_PARAMS( (int x) (bind this) ) { this_->g(x); //<<<<<<<<< Shall this be `_this->g(x);` instead? ... } BOOST_LOCAL_FUNCTIO_NAME(l) ... } ... };
In particular, some library uses _ postfix for statements like mpl::if_ (not mpl::_if) while other uses _ prefix for variables like phoenix::local_names::_f (not local_names::f_).
The convention is that _xxx is used for placeholders. xxx_ is used when xxx is a keyword.
I see, thanks. `this` is a keyword so Boost.Local should continue to use `this_` -- I'll add this to the docs rationale. -- Lorenzo

On Sun, Apr 3, 2011 at 8:28 PM, Lorenzo Caminiti <lorcaminiti@gmail.com> wrote:
On Sun, Apr 3, 2011 at 2:22 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
On 04/03/2011 11:13 AM, Lorenzo Caminiti wrote:
Boost.Local uses a special name `this_` to access the object `this` bound from the enclosing scope. Shall this name be `this_` or `_this` according to Boost practices?
struct c { void g(int x) { ... } void f() { void BOOST_LOCAL_FUNCTION_PARAMS( (int x) (bind this) ) { this_->g(x); //<<<<<<<<< Shall this be `_this->g(x);` instead? ... } BOOST_LOCAL_FUNCTIO_NAME(l) ... } ... };
In particular, some library uses _ postfix for statements like mpl::if_ (not mpl::_if) while other uses _ prefix for variables like phoenix::local_names::_f (not local_names::f_).
The convention is that _xxx is used for placeholders. xxx_ is used when xxx is a keyword.
I see, thanks. `this` is a keyword so Boost.Local should continue to use `this_` -- I'll add this to the docs rationale.
I use _this for the placeholder to the current lambda in Boost.Phoenix

On 4/4/2011 1:00 PM, Thomas Heller wrote:
On Sun, Apr 3, 2011 at 8:28 PM, Lorenzo Caminiti<lorcaminiti@gmail.com> wrote:
On Sun, Apr 3, 2011 at 2:22 PM, Steven Watanabe<watanabesj@gmail.com> wrote:
AMDG
On 04/03/2011 11:13 AM, Lorenzo Caminiti wrote:
Boost.Local uses a special name `this_` to access the object `this` bound from the enclosing scope. Shall this name be `this_` or `_this` according to Boost practices?
struct c { void g(int x) { ... } void f() { void BOOST_LOCAL_FUNCTION_PARAMS( (int x) (bind this) ) { this_->g(x); //<<<<<<<<< Shall this be `_this->g(x);` instead? ... } BOOST_LOCAL_FUNCTIO_NAME(l) ... } ... };
In particular, some library uses _ postfix for statements like mpl::if_ (not mpl::_if) while other uses _ prefix for variables like phoenix::local_names::_f (not local_names::f_).
The convention is that _xxx is used for placeholders. xxx_ is used when xxx is a keyword.
I see, thanks. `this` is a keyword so Boost.Local should continue to use `this_` -- I'll add this to the docs rationale.
I use _this for the placeholder to the current lambda in Boost.Phoenix
Thomas, I strongly suggest that it be renamed to this_ for consistency. Regards, -- Joel de Guzman http://www.boostpro.com http://boost-spirit.com

On 4/3/2011 10:34 PM, Joel de Guzman wrote:
On 4/4/2011 1:00 PM, Thomas Heller wrote:
On Sun, Apr 3, 2011 at 8:28 PM, Lorenzo
I see, thanks. `this` is a keyword so Boost.Local should continue to use `this_` -- I'll add this to the docs rationale.
I use _this for the placeholder to the current lambda in Boost.Phoenix
Thomas, I strongly suggest that it be renamed to this_ for consistency.
So it should be _this_ because it is a placeholder and it collides with a keywork (o; michael -- ---------------------------------- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com

On 4/4/2011 1:34 PM, Joel de Guzman wrote:
On 4/4/2011 1:00 PM, Thomas Heller wrote:
On Sun, Apr 3, 2011 at 8:28 PM, Lorenzo Caminiti<lorcaminiti@gmail.com> wrote:
On Sun, Apr 3, 2011 at 2:22 PM, Steven Watanabe<watanabesj@gmail.com> wrote:
AMDG
On 04/03/2011 11:13 AM, Lorenzo Caminiti wrote:
Boost.Local uses a special name `this_` to access the object `this` bound from the enclosing scope. Shall this name be `this_` or `_this` according to Boost practices?
struct c { void g(int x) { ... } void f() { void BOOST_LOCAL_FUNCTION_PARAMS( (int x) (bind this) ) { this_->g(x); //<<<<<<<<< Shall this be `_this->g(x);` instead? ... } BOOST_LOCAL_FUNCTIO_NAME(l) ... } ... };
In particular, some library uses _ postfix for statements like mpl::if_ (not mpl::_if) while other uses _ prefix for variables like phoenix::local_names::_f (not local_names::f_).
The convention is that _xxx is used for placeholders. xxx_ is used when xxx is a keyword.
I see, thanks. `this` is a keyword so Boost.Local should continue to use `this_` -- I'll add this to the docs rationale.
I use _this for the placeholder to the current lambda in Boost.Phoenix
Thomas, I strongly suggest that it be renamed to this_ for consistency.
I have to retract. Spirit too uses pre _ on *all* placeholders. So, IMO, Thomas is right in choosing _this. http://tinyurl.com/3e9msbb Regards. -- Joel de Guzman http://www.boostpro.com http://boost-spirit.com

On Sun, Apr 3, 2011 at 2:22 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
On 04/03/2011 11:13 AM, Lorenzo Caminiti wrote:
Boost.Local uses a special name `this_` to access the object `this` bound from the enclosing scope. Shall this name be `this_` or `_this` according to Boost practices?
struct c { void g(int x) { ... } void f() { void BOOST_LOCAL_FUNCTION_PARAMS( (int x) (bind this) ) { this_->g(x); //<<<<<<<<< Shall this be `_this->g(x);` instead? ... } BOOST_LOCAL_FUNCTIO_NAME(l) ... } ... };
In particular, some library uses _ postfix for statements like mpl::if_ (not mpl::_if) while other uses _ prefix for variables like phoenix::local_names::_f (not local_names::f_).
The convention is that _xxx is used for placeholders. xxx_ is used when xxx is a keyword.
1) What is the exact definition of a "placeholder"? 2) What is the convention for an xxx that is both a keyword and a placeholder? Thanks a lot. -- Lorenzo

AMDG On 04/05/2011 04:52 PM, Lorenzo Caminiti wrote:
On Sun, Apr 3, 2011 at 2:22 PM, Steven Watanabe<watanabesj@gmail.com> wrote:
On 04/03/2011 11:13 AM, Lorenzo Caminiti wrote:
Boost.Local uses a special name `this_` to access the object `this` bound from the enclosing scope. Shall this name be `this_` or `_this` according to Boost practices?
struct c { void g(int x) { ... } void f() { void BOOST_LOCAL_FUNCTION_PARAMS( (int x) (bind this) ) { this_->g(x); //<<<<<<<<< Shall this be `_this->g(x);` instead? ... } BOOST_LOCAL_FUNCTIO_NAME(l) ... } ... };
In particular, some library uses _ postfix for statements like mpl::if_ (not mpl::_if) while other uses _ prefix for variables like phoenix::local_names::_f (not local_names::f_).
The convention is that _xxx is used for placeholders. xxx_ is used when xxx is a keyword.
1) What is the exact definition of a "placeholder"?
A placeholder is an object or type which is intended to be replaced by another object or type. Some Examples of placeholder objects are _1, _2, etc, used in bind, lambda, and phoenix. Examples of placeholder types are mpl::_1, and boost::recursive_variant_. I would not consider this_ a placeholder here.
2) What is the convention for an xxx that is both a keyword and a placeholder?
The situation hasn't come up. In Christ, Steven Watanabe

On 4/6/2011 8:01 AM, Steven Watanabe wrote:
1) What is the exact definition of a "placeholder"?
A placeholder is an object or type which is intended to be replaced by another object or type. Some Examples of placeholder objects are _1, _2, etc, used in bind, lambda, and phoenix. Examples of placeholder types are mpl::_1, and boost::recursive_variant_.
In phoenix, it is a placeholder because _this is supposed to be replaced by /this/ when the function is evaluated and /this/ is a valid pointer at eval time. It is uses in, for example, recursive lambda functions. Regards, -- Joel de Guzman http://www.boostpro.com http://boost-spirit.com

On Tue, Apr 5, 2011 at 4:52 PM, Lorenzo Caminiti <lorcaminiti@gmail.com>wrote:
On Sun, Apr 3, 2011 at 2:22 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
On 04/03/2011 11:13 AM, Lorenzo Caminiti wrote:
Boost.Local uses a special name `this_` to access the object `this` bound from the enclosing scope. Shall this name be `this_` or `_this` according to Boost practices?
struct c { void g(int x) { ... } void f() { void BOOST_LOCAL_FUNCTION_PARAMS( (int x) (bind this) ) { this_->g(x); //<<<<<<<<< Shall this be `_this->g(x);` instead? ... } BOOST_LOCAL_FUNCTIO_NAME(l) ... } ... };
In particular, some library uses _ postfix for statements like mpl::if_ (not mpl::_if) while other uses _ prefix for variables like phoenix::local_names::_f (not local_names::f_).
The convention is that _xxx is used for placeholders. xxx_ is used when xxx is a keyword.
1) What is the exact definition of a "placeholder"?
My guess: Any object that gets implicitly bound upon the evaluation of its enclosing expression.
2) What is the convention for an xxx that is both a keyword and a placeholder?
My guess: Just use a leading underscore, as then it isn't a keyword anymore, so no need for a trailing underscore. I wouldn't consider your bound "this" variable *implicitly* bound, as it appears explicitly in the bind list, so I'm partial to "this_" (trailing underscore only). I also believe some variant of "this" is better than other suggestions like "that" and "self", because: - The bind list should use the keyword "this" to bind the current object, as that's the *only* thing "this" could mean. Any other keyword you choose *could* happen to be a local variable that the user *could* want to bind instead, and they'd be SOL. - The keyword used in the function body should match (as closely as possible) the keyword used in the bind list. Also, additional suggestion, but probably not a good one: You could provide a macro for any user to introduce a new name for the "this" variable within a Boost.Local block, similar to Boost.Tribool's macro that allows one to introduce a new name for the 3rd tribool state. So if one prefers "self", "_this", "this_", "that", etc., they will be free to do so. Of course, introducing multiple names for the same thing can easily make things confusing... - Jeff

On Sun, Apr 3, 2011 at 11:13 AM, Lorenzo Caminiti <lorcaminiti@gmail.com> wrote:
Hello all,
Boost.Local uses a special name `this_` to access the object `this` bound from the enclosing scope. Shall this name be `this_` or `_this` according to Boost practices?
Names with leading underscore should be avoided, they may be used by the compiler for its own needs. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

On Apr 3, 2011, at 12:22 PM, Emil Dotchevski wrote:
On Sun, Apr 3, 2011 at 11:13 AM, Lorenzo Caminiti <lorcaminiti@gmail.com
wrote: Hello all,
Boost.Local uses a special name `this_` to access the object `this` bound from the enclosing scope. Shall this name be `this_` or `_this` according to Boost practices?
Names with leading underscore should be avoided, they may be used by the compiler for its own needs.
A name beginning with an underscore not followed by a capital letter is allowable at non-global scope (provided it doesn't contain two consecutive underscores). Such names include _, _1, and _this. Josh

On Sun, Apr 3, 2011 at 1:12 PM, Joshua Juran <jjuran@gmail.com> wrote:
On Apr 3, 2011, at 12:22 PM, Emil Dotchevski wrote:
On Sun, Apr 3, 2011 at 11:13 AM, Lorenzo Caminiti <lorcaminiti@gmail.com> wrote:
Hello all,
Boost.Local uses a special name `this_` to access the object `this` bound from the enclosing scope. Shall this name be `this_` or `_this` according to Boost practices?
Names with leading underscore should be avoided, they may be used by the compiler for its own needs.
A name beginning with an underscore not followed by a capital letter is allowable at non-global scope (provided it doesn't contain two consecutive underscores). Such names include _, _1, and _this.
Granted, it is very unlikely _this to be used by the implementation, but I've seen compilers defining macros with leading underscore followed by a lowercase letter. There is no reason to insist on using leading underscores, in global scope or not. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

Emil Dotchevski wrote:
Granted, it is very unlikely _this to be used by the implementation, but I've seen compilers defining macros with leading underscore followed by a lowercase letter. There is no reason to insist on using leading underscores, in global scope or not.
Joshua Juran wrote:
A name beginning with an underscore not followed by a capital letter is allowable at non-global scope (provided it doesn't contain two consecutive underscores). Such names include _, _1, and _this.
Steven Watanabe wrote:
The convention is that _xxx is used for placeholders. xxx_ is used when xxx is a keyword.
Dear Boosters, All this talking of underscores makes me wonder about private class members. Several authors advise to give them names with a prefix underscore (followed by a lowercase letter). It does seem to have clear advantages: it visually marks the members as implementation details, and it also makes it easier to distinguish class member data from arguments and locally declared variables in member functions. However, your opinions probably differ wildly on the matter. Would you consider it good practice to give private class members a name that starts with _[a-z] (regex)? -Julian

Julian Gonggrijp wrote:
All this talking of underscores makes me wonder about private class members. Several authors advise to give them names with a prefix underscore (followed by a lowercase letter). It does seem to have clear advantages: it visually marks the members as implementation details, and it also makes it easier to distinguish class member data from arguments and locally declared variables in member functions.
However, your opinions probably differ wildly on the matter. Would you consider it good practice to give private class members a name that starts with _[a-z] (regex)?
Distinguishing private data members from local variables and formal parameters is useful. It creates a distinct "namespace" from local variable and formal parameter names. How to mark them is purely subjective. Some use the "m_" prefix, popularized by MFC and MSVC code generators, but I find that to be too much of a wart on the name. Some use "this->" as a prefix, so their data member names need no special marking. I like to distinguish protected and private data members but with a trailing underscore. I use a trailing underscore because it is less important than the data member's name. (I also use a preceding underscore for formal parameters to give them another "namespace." In that case, the underscore can't be on the end, of course.) _____ Rob Stewart robert.stewart@sig.com Software Engineer using std::disclaimer; Dev Tools & Components Susquehanna International Group, LLP http://www.sig.com IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

On Apr 18, 2011, at 7:41 AM, Stewart, Robert wrote:
Julian Gonggrijp wrote:
All this talking of underscores makes me wonder about private class members. Several authors advise to give them names with a prefix underscore (followed by a lowercase letter). It does seem to have clear advantages: it visually marks the members as implementation details, and it also makes it easier to distinguish class member data from arguments and locally declared variables in member functions.
However, your opinions probably differ wildly on the matter. Would you consider it good practice to give private class members a name that starts with _[a-z] (regex)?
Distinguishing private data members from local variables and formal parameters is useful. It creates a distinct "namespace" from local variable and formal parameter names. How to mark them is purely subjective. Some use the "m_" prefix, popularized by MFC and MSVC code generators, but I find that to be too much of a wart on the name. Some use "this->" as a prefix, so their data member names need no special marking.
I like to distinguish protected and private data members but with a trailing underscore. I use a trailing underscore because it is less important than the data member's name. (I also use a preceding underscore for formal parameters to give them another "namespace." In that case, the underscore can't be on the end, of course.)
I precede data member names with 'its_' (for nouns) or 'it_' (for boolean properties), e.g. its_window, it_is_selected. I chose third- person usage (as opposed to, say, "my") to match 'this'. I like self- documenting English notation. :-) Josh

Stewart, Robert wrote:
Distinguishing private data members from local variables and formal parameters is useful. It creates a distinct "namespace" from local variable and formal parameter names. How to mark them is purely subjective. Some use the "m_" prefix, popularized by MFC and MSVC code generators, but I find that to be too much of a wart on the name. Some use "this->" as a prefix, so their data member names need no special marking.
I like to distinguish protected and private data members but with a trailing underscore. I use a trailing underscore because it is less important than the data member's name. (I also use a preceding underscore for formal parameters to give them another "namespace." In that case, the underscore can't be on the end, of course.)
Joshua Juran wrote:
I precede data member names with 'its_' (for nouns) or 'it_' (for boolean properties), e.g. its_window, it_is_selected. I chose third-person usage (as opposed to, say, "my") to match 'this'. I like self-documenting English notation. :-)
Thank you for your opinions on this matter. -Julian

AMDG On 04/03/2011 12:22 PM, Emil Dotchevski wrote:
On Sun, Apr 3, 2011 at 11:13 AM, Lorenzo Caminiti<lorcaminiti@gmail.com> wrote:
Hello all,
Boost.Local uses a special name `this_` to access the object `this` bound from the enclosing scope. Shall this name be `this_` or `_this` according to Boost practices?
Names with leading underscore should be avoided, they may be used by the compiler for its own needs.
Names beginning with an underscore and a /capital/ letter are reserved for any use. Names beginning with an underscore and a lower-case letter are only reserved in the global namespace. In Christ, Steven Watanabe

On 4/3/2011 11:15 PM, Artyom wrote:
Boost.Local uses a special name `this_` to access the object `this` bound from the enclosing scope. Shall this name be `this_` or `_this` according to Boost practices?
Use "self"
_self would be most appropriate in that case. There is a long history of a preceding underscore for placeholders. Some of the libraries following this tradition include: bind, lambda, phoenix, spirit, and proto. When I see _foo I immediately think "placeholder". So, if it is a placeholder then I think the preceding underscore would sure be nice regardless of the name. michael -- ---------------------------------- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com
participants (12)
-
Artyom
-
Emil Dotchevski
-
Jeffrey Lee Hellrung, Jr.
-
Joel de Guzman
-
Joshua Juran
-
Julian Gonggrijp
-
Lorenzo Caminiti
-
Matt Calabrese
-
Michael Caisse
-
Steven Watanabe
-
Stewart, Robert
-
Thomas Heller