[cfe-dev] draft rule for naming types/functions/variables

Chris Lattner clattner at apple.com
Mon Nov 22 23:08:44 PST 2010


On Nov 22, 2010, at 5:16 PM, Zhanyong Wan (λx.x x) wrote:

> Hi guys,
> 
> Based on our discussion last week, I put together a new coding style
> rule regarding the naming of types/functions/variables.  I've uploaded
> the patch to
> 
> http://codereview.appspot.com/3264041
> 
> Please let me know what you think.  My idea is to start with something
> non-controversial such that we can get the baseline committed soon.
> We can then tweak the rule as needed later to cover more specific
> scenarios.  Thanks,

I think that the type/function name convention makes sense.

However, I don't fully agree for local variable names.  For them, there are two cases, things with small lifetimes where having a simple short name is good, and things with longer lifetimes where you want something descriptive.

For example, naming a variable i here is perfectly fine:

for (unsigned i = 0; i != 100; ++i)
  A[i] = 0;

Naming it "ArrayIndex" would not make it more clear :)

For capitalization, I generally prefer capital names with the exception being one character names that are often metasyntactic names (like i/j).

Also, since this applies to LLVM as a whole, I'd suggest moving this to llvmdev, which will reach a larger audience.

-Chris



More information about the cfe-dev mailing list