Thread overview | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
April 20, 2005 naming conventions | ||||
---|---|---|---|---|
| ||||
Hi What do you guys prefix to your private member variables, so that later you can create a property to access it later on? Would you do something like this? : class MyClass { private int _variable; int variable(){return _variable;} } |
April 20, 2005 Re: naming conventions | ||||
---|---|---|---|---|
| ||||
Posted in reply to imr1984 | imr1984 wrote: > What do you guys prefix to your private member variables, so that later you can > create a property to access it later on? m_variable is pretty common... ("m" is for member, I believe?) > Would you do something like this? : > > class MyClass > { > private int _variable; > > int variable(){return _variable;} > } Names starting with underscore are reserved for the compiler (such as _arguments and _argptr, and other "special" ones) --anders |
April 20, 2005 Re: naming conventions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anders F Björklund | Anders F Björklund wrote:
<snip>
>
> Names starting with underscore are reserved for the compiler
> (such as _arguments and _argptr, and other "special" ones)
>
> --anders
Where did you get this?
|
April 20, 2005 Re: naming conventions | ||||
---|---|---|---|---|
| ||||
Posted in reply to zwang | zwang wrote: >> Names starting with underscore are reserved for the compiler >> (such as _arguments and _argptr, and other "special" ones) > > Where did you get this? I'm afraid it was just hearsay, but it was "from Walter". However, such identifiers are reserved in the C language and the recent addition of a few new ones convinced me ? But now that I check again, it's only *two* underscores that are reserved by the D compiler... Sorry about that. http://www.digitalmars.com/d/lex.html#identifier --anders |
April 20, 2005 Re: naming conventions | ||||
---|---|---|---|---|
| ||||
Posted in reply to imr1984 | "imr1984" <imr1984_member@pathlink.com> wrote in message news:d4597r$2q0o$1@digitaldaemon.com... > Hi > > What do you guys prefix to your private member variables, so that later > you can > create a property to access it later on? > > Would you do something like this? : > > class MyClass > { > private int _variable; > > int variable(){return _variable;} > } I typically use a trailing "_data" or sometimes if I'm lazy just a trailing "_". So the property "variable" would have its data stored in "variable_data" or "vatiable_". The property "someMultiWordProp" would be "someMultiWordProp_data" or "someMultiWordProp_". I prefer _data since it stands out more than a _. Shortening the variable name is also an option but only if the class definition is small enough (eg a screenful) that it isn't confusing. |
April 20, 2005 Re: naming conventions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anders F Björklund | Anders F Björklund wrote:
> zwang wrote:
>
>>> Names starting with underscore are reserved for the compiler
>>> (such as _arguments and _argptr, and other "special" ones)
>>
>>
>> Where did you get this?
>
>
> I'm afraid it was just hearsay, but it was "from Walter".
> However, such identifiers are reserved in the C language
> and the recent addition of a few new ones convinced me ?
>
> But now that I check again, it's only *two* underscores
> that are reserved by the D compiler... Sorry about that.
> http://www.digitalmars.com/d/lex.html#identifier
>
> --anders
If memory serves me right, in the C language, identifiers starting with an underscore and a *lowercase* letter are not reserved.
|
April 20, 2005 Re: naming conventions | ||||
---|---|---|---|---|
| ||||
Posted in reply to zwang | zwang wrote:
> If memory serves me right, in the C language, identifiers starting with an underscore and a *lowercase* letter are not reserved.
I just find that various C compiler writers use underscore
names for all kinds of things, messing with my own names.
But I never saw that in a specification or anything...
--anders
|
April 20, 2005 Re: naming conventions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anders F Björklund | Anders F Björklund wrote:
> zwang wrote:
>
>> If memory serves me right, in the C language, identifiers starting with an underscore and a *lowercase* letter are not reserved.
>
>
> I just find that various C compiler writers use underscore
> names for all kinds of things, messing with my own names.
>
> But I never saw that in a specification or anything...
>
> --anders
The ANSI/ISO standard reserves all names that begin with two underscores or an underscore followed by a capital letter.
|
April 20, 2005 Re: naming conventions | ||||
---|---|---|---|---|
| ||||
Posted in reply to imr1984 | Does anyone else think that this horrible underscore name mangling business could be avoided if member variables were allowed to be public readonly? ie outside the scope of the class, variables can be read but not changed. In article <d4597r$2q0o$1@digitaldaemon.com>, imr1984 says... > >Hi > >What do you guys prefix to your private member variables, so that later you can create a property to access it later on? > >Would you do something like this? : > >class MyClass >{ >private int _variable; > >int variable(){return _variable;} >} > > |
April 20, 2005 Re: naming conventions | ||||
---|---|---|---|---|
| ||||
Posted in reply to imr1984 |
That is my way of naming private variables too. However D developers are more in JAVA mood, so they will probably name it somehow different...
--
...........
Dejan Lekic
http://dejan.lekic.org
|
Copyright © 1999-2021 by the D Language Foundation