variable naming
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
Personally, I would do it like this:
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.
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:
Hungarian notation prefaces member variables with an m_ .
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:
(though I personally prefer the m_ prefix for member variables)
int Create(float fWidth, float fHeight){ this->fWidth = fWidth; this->fHeight = fHeight;}
(though I personally prefer the m_ prefix for member variables)
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.
but I didn''t learn it when I started programming and I can''t
seem to force myself to switch.
Create.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement