Jump to content
  • Advertisement
Sign in to follow this  
Waaayoff

When the class name is the same as its instance...

This topic is 1698 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I run into this problem a lot. Sometimes a class's name is very simple. Like Renderer, Terrain, Brush, etc... Now you want to have an instance of that. What makes it harder for me is that i use upper camel case for members!

 

Suggestions?

Share this post


Link to post
Share on other sites
Advertisement

Renderer renderer; variable

Renderer mRenderer; class member field

Renderer pRenderer = new Renderer();  pointer variable

Renderer mpRenderer = new Renderer(); pointer class member field

 

This style works well and is recommended by the author of Code Complete.

Edited by EddieV223

Share this post


Link to post
Share on other sites

Upper camel case for variables seems unusual.

 

Really? I use lower case for function/local variables but upper case for member variables. Maybe i should switch to lower case or use a prefix like m.

Share this post


Link to post
Share on other sites

I just haven't seen them named that way. However I also have my own special non-conforming code guidelines, so do what you like :)

Share this post


Link to post
Share on other sites

My suggestion is if it bothers you to not be able to use the same name then just change your coding convention. Otherwise its really best if you find something at least a little more descriptive for the current use in a variable than the type name.

Personally I use like using upper camel case in C++ for things not changing at runtime like types, classes and methods; and lower camel case for variables. I dont see value in hungarian notation, thats why I dont use m prefixes.

Share this post


Link to post
Share on other sites

My suggestion is if it bothers you to not be able to use the same name then just change your coding convention. Otherwise its really best if you find something at least a little more descriptive for the current use in a variable than the type name.

Personally I use like using upper camel case in C++ for things not changing at runtime like types, classes and methods; and lower camel case for variables. I dont see value in hungarian notation, thats why I dont use m prefixes.

The m and p prefixes are not hungarian notation.  Hungarian notation involves prefixing with the type, such as i for int f for float and even coming up with your own prefixes for other classes.

 

The m p just denote the scope and either pointer or variable.

Share this post


Link to post
Share on other sites

 

My suggestion is if it bothers you to not be able to use the same name then just change your coding convention. Otherwise its really best if you find something at least a little more descriptive for the current use in a variable than the type name.
Personally I use like using upper camel case in C++ for things not changing at runtime like types, classes and methods; and lower camel case for variables. I dont see value in hungarian notation, thats why I dont use m prefixes.

The m and p prefixes are not hungarian notation.  Hungarian notation involves prefixing with the type, such as i for int f for float and even coming up with your own prefixes for other classes.
 
The m p just denote the scope and either pointer or variable.

 

Actually, I believe the original form of Hungarian Notation was closer to your example (see this), and became widely misused in the way you describe. /nitpick =)

Share this post


Link to post
Share on other sites

 

 

My suggestion is if it bothers you to not be able to use the same name then just change your coding convention. Otherwise its really best if you find something at least a little more descriptive for the current use in a variable than the type name.
Personally I use like using upper camel case in C++ for things not changing at runtime like types, classes and methods; and lower camel case for variables. I dont see value in hungarian notation, thats why I dont use m prefixes.

The m and p prefixes are not hungarian notation.  Hungarian notation involves prefixing with the type, such as i for int f for float and even coming up with your own prefixes for other classes.
 
The m p just denote the scope and either pointer or variable.

 

Actually, I believe the original form of Hungarian Notation was closer to your example (see this), and became widely misused in the way you describe. /nitpick =)

 

In either case it's nothing like my notation.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!