variable naming

Started by
13 comments, last by Zoney 22 years, 4 months ago
I''ve been trying to make my variable names more understandable, I''ve added prefixes according to type and stuff, but there''s just one small problem let''s say I have this imaginary sprite class with two member variables and one function class CSprite { private: float fWidth; float fHeight; public: int Create(float fWidth, float fHeight); }; in the create function I want to set the value of the two member variables, but the natural names for the parameter variables are taken by the member. How do you guys name your variables in this case? This is may seem like unnecessary post but I tend to be somewhat pedantic in my coding
"If there was no god, it would be necessary to invent one" - Voltaire
Advertisement
Personally, I would do it like this:

  class CSprite{public: int Create(float width, float height);private: float fWidth; float fHeight;};  


I just name my "permanent" variables with nice-looking prefixes and leave parameters without a prefix...

"That''s what I think anyway" - Mr Bean

---------------

I finally got it all together...
...and then forgot where I put it.
You could do:

  class CSprite{public: int Create(float fWidth, float fHeight){  m_fWidth = fWidth;  m_fHeight = fHeight; }private: float m_fWidth; float m_fHeight;};  


Hungarian notation prefaces member variables with an m_ .
..but to answer your original question, implement Create like this:

  int Create(float fWidth, float fHeight){  this->fWidth = fWidth;  this->fHeight = fHeight;}  


(though I personally prefer the m_ prefix for member variables)
... or just learn microsoft''s crazy Hungarian notation...which is pure evil >=D


JaRoS
JaRoS
Microsoft''s Hungarian notation is the light, you are the one who is evil... heathen. =)
what a stupid topic
what a stupid response
Actually, I think the Hungarian notation is quite logical,
but I didn''t learn it when I started programming and I can''t
seem to force myself to switch.

Create.
anyone know where to find a complete listing of all hungarian notation?
"If there was no god, it would be necessary to invent one" - Voltaire

This topic is closed to new replies.

Advertisement