lld: Coding Conventions

The goal is for lld to be eventually accepted by the LLVM community and become the standard linker used with clang. Therefore, the lld source code structure and style is following the LLVM Coding Standards with the exceptions noted below. The execptions are to solve real world problems such as disambiguation and avoiding bugs.

Type name versus non-type name disambiguation

Like the LLVM convention, lld uses camel case for names, and capital letters to begin the name of a type (e.g. Atom, Reference). But, unlike LLVM the lld convention is to begin non-type identifiers with a lower case letter, so they are easily distiguished (e.g. Foo is a type and foo is a variable). Here are some concrete examples of the problem with variables and types being named the same:


Member variable versus local variable disambiguation

Like the LLVM convention, lld uses camel case for variable names. But to disambiguate data members (aka instance variables, aka ivars) from local (stack) variables, lld adds a leading underscore to instance variable names (e.g. _file, _stringsMaxOffset are ivars). Think of the leading underbar as short hand for "this->".

It is important to quickly disambiguate ivars from local variables to understand the lifetime, scope, and what else might be using the variable.

C++ coding conventions of other projects

I did some web searching to see what other C++ conventions are documented. I found no other conventions in which type names and variable names could collide as can happen with the LLVM conventions. Here are some which are generally similar (camel case) to LLVM's conventions (e.g. not GNU or unix-like all lower case conventions).