Code style for property

XavierAP via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Mar 12 05:59:48 PDT 2017


On Sunday, 12 March 2017 at 11:15:04 UTC, Nicholas Wilson wrote:
> On Sunday, 12 March 2017 at 10:47:35 UTC, Andrey wrote:
>> And I want make access to read x, y and bar. Probably I should 
>> add prefix for private members, that is a question: what 
>> prefix should I use? Now I use prefix p_ (from the word 
>> property), but maybe prefix m_ is better and you need to use 
>> it for all private members?
>
> A single leading underscore is usually used to denote a private 
> variable ( names prefixed with two leading underscores are 
> reserved for use by the compiler).

If you need any prefix at all, a single underscore is enough, and 
it's also the tradition in other languages such as Python, C#... 
Whether a private member is exposed as property or in some other 
way, can be seen in the getter/setter, no need to classify it 
into the member declaration.

C++ kind or requires a letter on top such as m_ simply because 
any identifiers starting with an underscore are (mostly and 
certainly at the global scope) reserved (namespace pollution 
anyone?).

It's really up to you, we won't call the police ;)


More information about the Digitalmars-d-learn mailing list