[llvm-dev] changing variable naming rules in LLVM codebase

Chris Lattner via llvm-dev llvm-dev at lists.llvm.org
Wed Feb 13 01:00:08 PST 2019



> On Feb 12, 2019, at 4:02 AM, Björn Pettersson A via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> (Sorry if this subject already has been discussed, but I could not find any clear rules/recommendations.)
>  
> What would the recommendation be for acronyms (I’ve seen the rule about avoiding them unless they are “well known”,
> but sometimes an acronym is useful, and we at least need to have some recommendation for the “well known” ones).
>  
> Example:
>  
>     if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
>       if (CE->getOpcode() == Instruction::GetElementPtr &&
>           CE->getOperand(0)->isNullValue()) {
>  
> In the above example, is the recommendation to use “ce” instead of “CE” now? Or should it be “cE”?
> With lowerCamelCase one might think that “cE” is the correct one (although I personally think that one looks quite ugly).

In most examples, you’d use something other than an initialism.  I was the one who started the whole CE thing as a contraction of the type into something short, but there are almost always things that work otherwise.  For example, I’d now write that example as:


    if (ConstantExpr *expr = dyn_cast<ConstantExpr>(value))
      if (expr->getOpcode() == Instruction::GetElementPtr &&
          expr->getOperand(0)->isNullValue()) {

or perhaps ‘constant' instead of ‘expr’.
 
> Maybe there should be an exception that variable names that start with an acronym still should start with an upper case letter?

That would also be fine with me - it could push such a debate down the road, and is definitely important for a transition period anyway.

-Chris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190213/82743b34/attachment-0001.html>


More information about the llvm-dev mailing list