Dnia Fri, 23 Mar 2007 23:54:57 -0700, Jim Langston napisa³(a):
int m_some_value;
is pretty much agreed that polish notation is dead.
Isn't it called 'hungarian notation'?
Polish notation [and reverse polish notation] is for expressions
I.e. '2 + 2' in PN is '+ 2 2' and in RPN is '2 2 +' .
A lot of people (myself included) add a training
trailing
underscore to private variables of a class.
I personally don't like names with leading or trailing underscores,
because it's easy to overlook them or confuse with other syntax.
But in the middle [separating words, when space isn't allowable] is OK.
Capitalization is another thing that people don't universially
follow one way or another. Personally, I would use SomeValue.
Some people would use someValue, although I've never understood why.
To differentiate object names from type names and method names.
I'm trying to use convention that object names start with small letter,
and the beginnings of the following words start with capital leter.
For type and function names the same, but I start with capital leter.
Then I always know where I have object name, and where the type name.
Example:
class GraphicsMode //new type name
{
public:
unsigned int ScreenWidth() const { return screenWidth; }
unsigned int ScreenHeight() const { return screenHeight; }
void ScreenWidht(unsigned int newScreenWidth); //set new width
void ScreenHeight(unsigned int newScreenHeight); //set new height
...
private:
unsigned int screenWidth;
unsigned int screenHeight;
...
};
//Now it's easy to see where is a type name, and where is object name.
GraphicsMode currentGraphicsMode;
//It's even possible to do the following, and it's stil clear.
GraphicsMode graphicsMode;
graphicsMode.ScreenWidth(123);
graphicsMode.ScreenHeight( currentGraphicsMode.ScreenHeight() );
Some_Value users would seem to be in the minority.
Yes. Because capitalization of first letter is enough information
to not confuse the particular words. Then the undesrcore would be
redundant
I am one of the very few people who still use polish notation for class
names. So I personally would do it this way:
class CMyClass
{
public:
int Value() { return Value_; }
private:
int Value_;
};
Hungarian notation has a one big flaw: when you want to change
the type of the name, you have to find-and-replace in the whole
source code [often in a whole bunch of source files].
What if you consider one day, that CMyClass is too simple for
a class, and it will be better as a plain old struct? Will you
find-and-replace all CMyClass to change it to SMyClass?
And it's in the most cases redundant to use hungarian notation,
because you're doing the compiler's work. It's a compiler's duty
to watch for a types of objects, not the programmer's.
It's better to write program by the way that you can know the
type of object from a context, not from prefixes.
Everyone pretty much agrees, however, never preceed a variable
name with an underscore. I.E. This is bad:
_Value;
Yes. And it's always as strange for me, that I always know that
here's something uncommon [implementation-defined name].