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

Chris Lattner clattner at apple.com
Fri Aug 12 13:29:04 PDT 2011


On Aug 12, 2011, at 1:19 PM, John McCall wrote:

> 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.

I can see where you're going on this, but there are several specific concerns I have:

1) this interferes with contractions like the much lauded "LI".  Using "li" doesn't read right and is harder to parse.
2) If it's hard to tell whether a variable is local or not, it is named poorly.  Variable names should be descriptive if they have a large scope, and short if they don't.  If it is hard to tell whether something is a local variable, something else is going wrong.

-Chris

> 
> 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.
> 
> John.
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list