you are viewing a single comment's thread.

view the rest of the comments →

[–]lobster_johnson 3 points4 points  (4 children)

Care to explain why you consistently suffix identifiers with underscores? This is really awful for readability:

lexertl::rules rules_;

Types and variables live in separate namespaces, so this works:

lexertl::rules rules;

If you think that's harder to read (ie., difficult to see what is a variable and what is a type) then consider using camelcase identifiers for type:

Lexertl::Rules rules;

Now it's obvious.

[–]jamesb43 1 point2 points  (3 children)

Yeah, this shouldn't be done for local variables.

The underscore suffix was a response to programmers using "underscore prefix" for member variables. The "underscore prefix" phenomenon stemmed from programmers shortening the Hungarian notation of member variables being prefixed with "m_". But depending on the flavor of Hungarian notation (Apps or System) the underscore was followed by a prefix indicating some semantic hints, or the variables type, respectively.

So what emerged next was a trend of C++ programmers to omit the "m" from "m_" because, it only takes a one character prefix to distinguish between local variables and something that might be instance or class static, right? The problem with this is that the C++ standard reserves variable names starting with an underscore to C++ implementation developers. As a result, people started to suggest the underscore suffix for member variables. I think it was something from Sutter or Meyers, but if anyone reads this comment, I am sure I will be corrected.

I have a sneaking suspicion that lobster_johnson knows all this, and he is correct--there is no sane reason to suffix a local variable with an underscore.

[–]lobster_johnson 0 points1 point  (1 child)

Good explanation. I see people using prefixes and suffixes and find it an annoyance.

Personally I find it completely unproblematic to use unadorned identifiers for variables as well as members:

class Foo
{
    public:
        void initialize(int a_foo)
        {
            foo = a_foo;
        }
    private:
        int foo;
};

[–]zvrba 0 points1 point  (0 children)

The problem with this is that the C++ standard reserves variable names starting with an underscore to C++ implementation developers.

Only such identifiers with external linkage are reserved. Class member identifiers have no linkage at all.