Jump to page: 1 2 3
Thread overview
proposal for a standard way to name member function arguments...
Jul 31, 2004
clayasaurus
Jul 31, 2004
h3r3tic
Aug 01, 2004
me
Aug 01, 2004
C. Sauls
Aug 01, 2004
James Widman
Jul 31, 2004
Deja Augustine
Jul 31, 2004
clayasaurus
Jul 31, 2004
h3r3tic
Aug 01, 2004
Matthew
Aug 01, 2004
Andy Friesen
Aug 01, 2004
clayasaurus
Aug 01, 2004
Matthew
Jul 31, 2004
Matthew
Hungarian Notation (was ...a standard way to name ... arguments)
Aug 01, 2004
Arcane Jill
Aug 01, 2004
parabolis
Aug 01, 2004
Andy Friesen
Aug 01, 2004
parabolis
Aug 01, 2004
Matthew
Aug 02, 2004
Arcane Jill
Aug 02, 2004
Regan Heath
Aug 03, 2004
Arcane Jill
Jul 31, 2004
Derek
Aug 03, 2004
Farmer
Aug 03, 2004
Derek
Aug 04, 2004
Farmer
Aug 04, 2004
Daniel Horn
Aug 04, 2004
Bent Rasmussen
Aug 01, 2004
J Anderson
July 31, 2004
hello, I'm having a simple problem. Let's say I have a class

class Foo
{
int size; // size var

this(int _size) // size this will set it
{
size = _size; // set size to size
}
}

the problem is that I have to _size for the function var.
To me this seems messy, I could also use sizevar or some other strange name but
I
feel _size is the closest I could get to size.

What I wouldn't mind is a standard way to declare, for member functions at
least,
something that would help tell it apart from the class member variables.

Maybe something like this...

class Foo
{
int size;

this(int @size) // the '@' signifies it as a member function argument
{
size = @size; // this way you can tell member vars from function arguments
}

}

so does anyone else think something like this would be good? is there a better solution already available?







July 31, 2004
clayasaurus wrote:
> hello, I'm having a simple problem. Let's say I have a class
> 
> class Foo
> {
> int size; // size var
> 
> this(int _size) // size this will set it
> {
> size = _size; // set size to size
> }
> }
> 
> the problem is that I have to _size for the function var. To me this seems messy, I could also use sizevar or some other strange name but
> I feel _size is the closest I could get to size. 

How about just using m_size for member vars. I think it's quite a standard naming convention...


> What I wouldn't mind is a standard way to declare, for member functions at
> least, something that would help tell it apart from the class member variables. 
> 
> Maybe something like this...
> 
> class Foo
> {
> int size; 
> 
> this(int @size) // the '@' signifies it as a member function argument {
> size = @size; // this way you can tell member vars from function arguments
> }
> 
> }
> 
> so does anyone else think something like this would be good? is there a better solution already available? 

If we were to go that way somehow, @ should be used for member vars, not for params. It's how Ruby does it, so some ppl would already be familiar with that thing.
July 31, 2004
clayasaurus wrote:

> hello, I'm having a simple problem. Let's say I have a class
> 
> class Foo
> {
> int size; // size var
> 
> this(int _size) // size this will set it
> {
> size = _size; // set size to size
> }
> }
> 
> the problem is that I have to _size for the function var. To me this seems messy, I could also use sizevar or some other strange name but
> I feel _size is the closest I could get to size. 
> 
> What I wouldn't mind is a standard way to declare, for member functions at
> least, something that would help tell it apart from the class member variables. 
> 
> Maybe something like this...
> 
> class Foo
> {
> int size; 
> 
> this(int @size) // the '@' signifies it as a member function argument {
> size = @size; // this way you can tell member vars from function arguments
> }
> 
> }
> 
> so does anyone else think something like this would be good? is there a better solution already available? 
> 
> 

All I have to say, and this is with no great offense intended, is yuck.  I'm not sure if this works in D, and I don't have the time to test it, but you could always try:

class Foo
{
	int size; // size var

	this(int size)
	{
		this.size = size;
	}
}
or just forget about it entirely.  Especially in that kind of a function, it doesn't matter what you call it, all people care about is that you have a class Foo that has a constructor that takes an integer size.  You could call it this(int max) for all people'd care.

Heck, you could do:

this(int bazooka) // ctor to set the default size
{

}

if you really wanted.  I don't think it's worthy of adding a new symbol to the lexicon just to distinguish fields from locals.

-Deja
July 31, 2004
In article <cegd35$13h1$1@digitaldaemon.com>, Deja Augustine says...
>
>clayasaurus wrote:
>
>> hello, I'm having a simple problem. Let's say I have a class
>> 
>> class Foo
>> {
>> int size; // size var
>> 
>> this(int _size) // size this will set it
>> {
>> size = _size; // set size to size
>> }
>> }
>> 
>> the problem is that I have to _size for the function var.
>> To me this seems messy, I could also use sizevar or some other strange name but
>> I
>> feel _size is the closest I could get to size.
>> 
>> What I wouldn't mind is a standard way to declare, for member functions at
>> least,
>> something that would help tell it apart from the class member variables.
>> 
>> Maybe something like this...
>> 
>> class Foo
>> {
>> int size;
>> 
>> this(int @size) // the '@' signifies it as a member function argument
>> {
>> size = @size; // this way you can tell member vars from function arguments
>> }
>> 
>> }
>> 
>> so does anyone else think something like this would be good? is there a better solution already available?
>> 
>> 
>
>All I have to say, and this is with no great offense intended, is yuck.
>  I'm not sure if this works in D, and I don't have the time to test it,
>but you could always try:
>
>class Foo
>{
>	int size; // size var
>
>	this(int size)
>	{
>		this.size = size;
>	}
>}
>or just forget about it entirely.  Especially in that kind of a
>function, it doesn't matter what you call it, all people care about is
>that you have a class Foo that has a constructor that takes an integer
>size.  You could call it this(int max) for all people'd care.
>
>Heck, you could do:
>
>this(int bazooka) // ctor to set the default size
>{
>
>}
>
>if you really wanted.  I don't think it's worthy of adding a new symbol to the lexicon just to distinguish fields from locals.
>
>-Deja

I think I'll just use the this.membervar way then. That seems to work. thx.


July 31, 2004
clayasaurus wrote:

>>class Foo
>>{
>>	int size; // size var
>>
>>	this(int size)
>>	{
>>		this.size = size;
>>	}
>>}
> 
> I think I'll just use the this.membervar way then. That seems to work. thx. 
> 
> 


K, this seems nice, just don't use the 'size' name or you'll have problems :)
July 31, 2004
Simple, decorate your member variables.

I use m_ (instance / non-static) and sm_ (class / static).  This is what DTL (and STLSoft) uses.

Other schemes are using a _ postfix, which is ok, but less good.

A bad one is using a _ prefix, since that breeds this bad habit elsewhere, and some languages (including D, in some respects, I think) reserve this for the implementation (i.e. the compiler vendor and/or the standard)

The worst of the lot is to have no decoration, since any reader of your code cannot immediately see what are member variables and what are local and/or module/namespace/global variables (for which s_ or g_ can be used). Furthermore, if you forget the this. in member initialisation, your code will have hidden bugs. Very poor.

(Interestingly - and Yes! he's plugging again - I'm working through the final layout proofs of Imperfect C++ at the moment, and have just covered this in chapter 17 - Syntax. Honesty compels me to recommend you pre-order this gem, due out Sept 9th. <G>)



"clayasaurus" <clayasaurus_member@pathlink.com> wrote in message news:cegc93$139u$1@digitaldaemon.com...
> hello, I'm having a simple problem. Let's say I have a class
>
> class Foo
> {
> int size; // size var
>
> this(int _size) // size this will set it
> {
> size = _size; // set size to size
> }
> }
>
> the problem is that I have to _size for the function var.
> To me this seems messy, I could also use sizevar or some other strange name but
> I
> feel _size is the closest I could get to size.
>
> What I wouldn't mind is a standard way to declare, for member functions at
> least,
> something that would help tell it apart from the class member variables.
>
> Maybe something like this...
>
> class Foo
> {
> int size;
>
> this(int @size) // the '@' signifies it as a member function argument
> {
> size = @size; // this way you can tell member vars from function arguments
> }
>
> }
>
> so does anyone else think something like this would be good? is there a better solution already available?
>
>
>
>
>
>
>



July 31, 2004
On Sat, 31 Jul 2004 15:01:55 +0000 (UTC), clayasaurus wrote:

> hello, I'm having a simple problem. Let's say I have a class
> 
> class Foo
> {
> int size; // size var
> 
> this(int _size) // size this will set it
> {
> size = _size; // set size to size
> }
> }
> 
> the problem is that I have to _size for the function var.
> To me this seems messy, I could also use sizevar or some other strange name but
> I
> feel _size is the closest I could get to size.
> 
> What I wouldn't mind is a standard way to declare, for member functions at
> least,
> something that would help tell it apart from the class member variables.
> 
> Maybe something like this...
> 
> class Foo
> {
> int size;
> 
> this(int @size) // the '@' signifies it as a member function argument
> {
> size = @size; // this way you can tell member vars from function arguments
> }
> 
> }
> 
> so does anyone else think something like this would be good? is there a better solution already available?

For what its worth, for the last many-years now, I've generally been prefixing my identifer names with a code that indicates scope and static-ness. It doesn't take long to write and makes reading code a lot easier.

 class Foo
 {
   private:
    int cSize; // size var

   public:
    this(int piSize) // size this will set it
    {
      cSize = piSize; // set size to size
    }
 }

"c" -->  "class" variable
"pi" --> "parameter in"
"po" --> "parameter out"
"pu" --> "parameter i/o"
"g"  --> "global" / public
"k"  --> "constant" / "static"
"l"  --> "local" to routine
"m"  --> scoped to module

Well it works for me; YMMV

-- 
Derek
Melbourne, Australia
August 01, 2004
> How about just using m_size for member vars. I think it's quite a standard naming convention...

fSize would be my vote. f as in field. Field being a proper OO term along with attribute and operation.

The @ doesn't read righ if you've ever done any pascal, because @x in pascal is the same as &x in C.

Matt

August 01, 2004
me wrote:
> The @ doesn't read righ if you've ever done any pascal, because @x in pascal
> is the same as &x in C.

Doesn't read right to anyone familiar with MOO or ColdC either, where @ is used to unbox lists.  Aka, in ColdC I'd do something like:

	foo = [1, 2, 3, 4, 5];
	.bar(@foo);  // the same as doing: .bar(1, 2, 3, 4, 5)

-Chris S.
-Invironz
August 01, 2004
clayasaurus wrote:

>hello, I'm having a simple problem. Let's say I have a class
>
>class Foo
>{
>int size; // size var
>
>this(int _size) // size this will set it
>{
>size = _size; // set size to size
>}
>}
>
>the problem is that I have to _size for the function var. To me this seems messy, I could also use sizevar or some other strange name but
>I feel _size is the closest I could get to size. 
>
>What I wouldn't mind is a standard way to declare, for member functions at
>least, something that would help tell it apart from the class member variables. 
>
>Maybe something like this...
>
>class Foo
>{
>int size; 
>
>this(int @size) // the '@' signifies it as a member function argument {
>size = @size; // this way you can tell member vars from function arguments
>}
>
>}
>
>so does anyone else think something like this would be good? is there a better solution already available? 
>  
>

I just use lower case (first letter) for parameters and upper for members.


-- 
-Anderson: http://badmama.com.au/~anderson/
« First   ‹ Prev
1 2 3