Thread overview
Naming corresponding properties, internal variables and arguments
Apr 26, 2004
Stewart Gordon
Apr 26, 2004
Norbert Nemec
Apr 26, 2004
Andy Friesen
Apr 26, 2004
Ant
April 26, 2004
For a typical property there are three things to name:

- the property itself
- the internal variable tracking its value
- the parameter to the setter function, and maybe also a constructor

(Obviously such a property is likely to have conversions, side effects or something involved....)

At the moment I'm not settled for any consistent way of naming such things.  Obviously the property name should be something human-readable. As for the others, I can see a few possibilities:

(a) Silly little capitalisation variations (arguably not good style).

(b) A little bit of Hungarian notation (also in contravention of the D style).

(c) Make the setter parameter an abbreviated form of the property name, and the internal variable something in between (or vice versa).

(d) Use the ability of parameter names to conflict with member names, make the internal variable name an abbreviation, and use one of these for the parameter name.  For a setter, it would obviously be abbreviated, perhaps to a single letter.  For a constructor, it could be the same.  Unless you want to make the parameter names human-readable so that auto-generated documentation is....

What do people think?  Or maybe there's a better idea than a, b, c or d?

Stewart.

-- 
My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment.  Please keep replies on the 'group where everyone may benefit.
April 26, 2004
I usually use prefix underscores for the internal variable and prefix "a_" for arguments.

----------------------------
class MyClass {
        private int _myproperty;

        this(int a_myproperty) { _myproperty = a_myproperty; }

        int myproperty() {
                dosomething();
                return _myproperty;
        }

        void myproperty(int a_myproperty)
                _myproperty = a_myproperty;
                dosomethingelse();
        }
}
----------------------------

Stewart Gordon wrote:

> For a typical property there are three things to name:
> 
> - the property itself
> - the internal variable tracking its value
> - the parameter to the setter function, and maybe also a constructor
> 
> (Obviously such a property is likely to have conversions, side effects
> or something involved....)
> 
> At the moment I'm not settled for any consistent way of naming such things.  Obviously the property name should be something human-readable. As for the others, I can see a few possibilities:
> 
> (a) Silly little capitalisation variations (arguably not good style).
> 
> (b) A little bit of Hungarian notation (also in contravention of the D
> style).
> 
> (c) Make the setter parameter an abbreviated form of the property name,
> and the internal variable something in between (or vice versa).
> 
> (d) Use the ability of parameter names to conflict with member names, make the internal variable name an abbreviation, and use one of these for the parameter name.  For a setter, it would obviously be abbreviated, perhaps to a single letter.  For a constructor, it could be the same.  Unless you want to make the parameter names human-readable so that auto-generated documentation is....
> 
> What do people think?  Or maybe there's a better idea than a, b, c or d?
> 
> Stewart.
> 

April 26, 2004
Stewart Gordon wrote:
> For a typical property there are three things to name:
> 
> - the property itself
> - the internal variable tracking its value
> - the parameter to the setter function, and maybe also a constructor

I prefix member variables with an underscore and for the property setter always use "value" like C#:

class SomeClass
{
	int _counter;

	this(int counter) { _counter = counter; }
	this() { this(0); }

	int counter()
	{
		return _counter;
	}

	void counter(int value)
	{
		_counter = value;
	}
}



-----
Julio César Carrascal Urquijo

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS$ d- s+:+ a-- C++> ULS++ P++ L+> !E W+++ N+ o? K? w++>
O---@ M V? PS+ PE Y+ PGP t+ 5- X+++@ R- tv+(++) b++> DI!
D++> G e+> h-- r- y+
------END GEEK CODE BLOCK------
April 26, 2004
Stewart Gordon wrote:

> For a typical property there are three things to name:
> 
> - the property itself
> - the internal variable tracking its value
> - the parameter to the setter function, and maybe also a constructor
> 
> (Obviously such a property is likely to have conversions, side effects or something involved....)
> 
> At the moment I'm not settled for any consistent way of naming such things.  Obviously the property name should be something human-readable. As for the others, I can see a few possibilities:
> 
> (a) Silly little capitalisation variations (arguably not good style).
> 
> (b) A little bit of Hungarian notation (also in contravention of the D style).
> 
> (c) Make the setter parameter an abbreviated form of the property name, and the internal variable something in between (or vice versa).
> 
> (d) Use the ability of parameter names to conflict with member names, make the internal variable name an abbreviation, and use one of these for the parameter name.  For a setter, it would obviously be abbreviated, perhaps to a single letter.  For a constructor, it could be the same.  Unless you want to make the parameter names human-readable so that auto-generated documentation is....
> 
> What do people think?  Or maybe there's a better idea than a, b, c or d?

I just use underscores for the attribute, and give the property the undecorated name.  Argument names have such tiny scope (especially in the case of getters and setters) that it doesn't really matter what you call them.

ie
   class A {
      private int _blah;

      int blah() { return _blah; }
      void blah(int whatever) { _blah = whatever; }
   }

 -- andy
April 26, 2004
In article <c6jafr$bnh$1@digitaldaemon.com>, Andy Friesen says...
>
>Stewart Gordon wrote:
>
>> For a typical property there are three things to name:
>> 
>> - the property itself
>> - the internal variable tracking its value
>> - the parameter to the setter function, and maybe also a constructor
>
>I just use underscores for the attribute, and give the property the undecorated name.  Argument names have such tiny scope (especially in the case of getters and setters) that it doesn't really matter what you call them.
>
>ie
>    class A {
>       private int _blah;
>
>       int blah() { return _blah; }
>       void blah(int whatever) { _blah = whatever; }
>    }
>

But be aware that intellisense (at least for eclipse and leds)
displays the argument name to the user.
here "newBlah" would be better then "whatever".

leds intellisense doesn't know about properties,
if it's a method it will be shown as a method.

I'm still sceptical about properties.

Ant
(wait for a new leds release with better intellisense (actually usable!)
tonight, unless... ;)