local variable naming convention
Boyd
gaboonviper at gmx.net
Fri Dec 20 03:16:31 PST 2013
On Friday, 20 December 2013 at 10:29:26 UTC, Jeremy DeHaan wrote:
> On Friday, 20 December 2013 at 10:06:36 UTC, Jonathan M Davis
> wrote:
>> Whereas I put the underscore before (e.g. _x), and some folks
>> like to do m_x
>> (though I haven't seen many people do that in D - more in C++).
>
>
> I tend to use the m_x naming convention, though I limit it to
> private member variables. Otherwise I stick to camelCase.
>
> If it is a parameter that is just going to be assigned to a
> member variable and they would otherwise have the same name, I
> usually add a prefix to parameter name to differentiate the
> two. In constructors it is usually "the" and in setters it is
> usually "new." Something like:
>
> this(string theTitle)
> {
> title = theTitle;
> }
>
> void setTitle(string newTitle)
> {
> title = newTitle;
> }
I've never seen the use of "the" before. I must say I like the
sound of it better than using 'title_'. I'm not a big fan of
arbitrary signs, even though I use '_title' if there is already
setter called 'title'
For setter parameters I tend to use 'value', though now that
might compromise certain cases where 'value' is already a member.
I do occasionally use 'new' as well, so I'll probably start using
that.
What does m_ stand for anyway?
More information about the Digitalmars-d-learn
mailing list