[llvm-commits] [llvm] r137497 - /llvm/trunk/docs/CodingStandards.html

John McCall rjmccall at apple.com
Fri Aug 12 13:19:55 PDT 2011

On Aug 12, 2011, at 12:49 PM, Chris Lattner wrote:
> URL: http://llvm.org/viewvc/llvm-project?rev=137497&view=rev
> Log:
> apparently variable naming conventions never got added, document the
> prevailing convention.

Aww.  I was doing my bit to change the prevailing convention.

I know this is a bikeshed topic, but I actually dislike this convention
quite a bit.  There's value in being able to tell, at a glance, what kind
of declaration an identifier refers to.   Functions are already
distinguished because (in all but vanishingly uncommon cases)
they're immediately followed by a left-paren.  Namespaces are
distinguished because they're always followed by :: (and they're
not capitalized, and so aren't confusable with types — a good
example of good capitalization rules clarifying the code!).  Enums
are distinguished because of the prefix mangling.   But the
"capitalize everything else" convention makes it impossible
to distinguish between different kinds of variables and fields, and
those are frequently used in analogous situations and are very
useful to distinguish.

My proposed rule would be that all variables and fields *except*
local variables should be capitalized.  Since that leaves the more
ambiguous/unknown case capitalized, migrating slowly to that
convention is pretty painless — you see a capitalized name,
so you don't know where it's declared, and you have to find it.
That's what we all have to do now.  Eventually, as lowercase
locals become more prevalent, you see one and unambiguously
know it's local:  a strict improvement in the information conveyed
by the code.

I would be willing to allow an exception for very short variable
names which are obviously abbreviations, since those should
never be non-local anyway.


More information about the llvm-commits mailing list