[LLVMdev] Guidance on using pointers vs. references for function arguments

Andrew Trick atrick at apple.com
Fri May 30 11:02:26 PDT 2014


On May 28, 2014, at 11:20 AM, David Chisnall <David.Chisnall at cl.cam.ac.uk> wrote:

> On 28 May 2014, at 15:46, Artyom Skrobov <Artyom.Skrobov at arm.com> wrote:
> 
>> I understand that for experienced contributors who work extensively on a
>> part of LLVM, the "local conventions" can seem natural and unobtrusive; but
>> for a newcomer, "getting a feel" for such ambiguous, implicit conventions is
>> just a speed-bump in the way of contributing to the project.
> 
> For experienced contributors *who stay within one part of the code*, this may be true.  For those of us who work on clang, the back end, and anything in between, the cognitive load to work out at any particular level which are the types that are expected to be pointers and which are expected to be references is quite high, especially as there are a number of things that are in the usually-pointers category in some parts of the codebase and the usually-references category in others.  


For new code, I follow Chris’ guideline. It’s the only effective way I know of reduce this cognitive load: "pointers for "classes" everywhere, references for value types, and pass by value when it is >= the efficiency of pass by value for value types.”

-Andy



More information about the llvm-dev mailing list