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

Tobias Grosser tobias at grosser.es
Fri Aug 12 14:43:07 PDT 2011


On 08/12/2011 09:29 PM, Chris Lattner wrote:
>
> 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.

You may also want to update the example in the coding conventions:

---------------------------------
Vehicle MakeVehicle(VehicleType Type) {
   VehicleMaker M                         // Might be OK if having a
                                             short life-span.
   Tire tmp1 = M.makeTire();               // Bad -- 'tmp1' provides no
                                              information.
   Light headlight = M.makeLight("head");  // Good -- descriptive.
   ...
}
---------------------------------

As far as I understood both 'tmp1' and 'headlight' should start with an 
uppercase letter.

Tobi



More information about the llvm-commits mailing list