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

John McCall rjmccall at apple.com
Fri Aug 12 14:49:12 PDT 2011


On Aug 12, 2011, at 1:59 PM, Jakob Stoklund Olesen wrote:
> On Aug 12, 2011, at 1:19 PM, John McCall wrote:
>> 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.
> 
> It's an established convention in libCodeGen to use abbreviations for class members representing the current context:
> 
> class AsmPrinter : public MachineFunctionPass {
>    TargetMachine &TM;
>    const MCAsmInfo *MAI;
>    const MachineFunction *MF;
>    MachineModuleInfo *MMI;
>    MachineLoopInfo *LI;
>    DwarfDebug *DD;
>    DwarfException *DE;
> }
> 
> The common abbreviations are mostly standardized which helps a lot.  Terms like MF, MRI, TRI, and TII are instantly recognizable.  These objects are effectively singletons within a pass, so they don't need real names.  Sometimes they are locals, sometimes they are members, it doesn't matter - there is only one object.

Yes, this is a common idiom in Clang as well for holding certain
"contextual singletons" — personally, I think pushing it down to
two-letter abbreviations is pretty unfortunate, but if those
abbreviations are actually recognizable and used commonly and
consistently then it's worth it.

It's the bulk of other objects that are neither iteration variables
nor singletons that I'm more concerned with.  Most of them are
local;  some aren't;  you generally have to already know the code
intimately to know the difference.

John.



More information about the llvm-commits mailing list