michaelplatings created this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Following discussion <http://lists.llvm.org/pipermail/llvm-dev/2019-February/129854.html> and general agreement that the current naming rule for variables is not ideal, this patch switches the naming rule to make `lowerCamelCase` the standard, consistent with a prior RFC <http://lists.llvm.org/pipermail/llvm-dev/2014-October/077685.html>. Given that over 450,000 variables are currently named in `UpperCamelCase`, the rule also permits using that form for consistency with existing code. I can't see a way to express that in .clang-tidy files. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D57896 Files: .clang-tidy clang/.clang-tidy llvm/.clang-tidy llvm/docs/CodingStandards.rst
Index: llvm/docs/CodingStandards.rst =================================================================== --- llvm/docs/CodingStandards.rst +++ llvm/docs/CodingStandards.rst @@ -1191,8 +1191,9 @@ nouns and start with an upper-case letter (e.g. ``TextFileReader``). * **Variable names** should be nouns (as they represent state). The name should - be camel case, and start with an upper case letter (e.g. ``Leader`` or - ``Boats``). + be camel case, and start with a lower case letter (e.g. ``leader`` or + ``boats``). It is also acceptable to use ``UpperCamelCase`` for consistency + with existing code. * **Function names** should be verb phrases (as they represent actions), and command-like function should be imperative. The name should be camel case, @@ -1232,16 +1233,22 @@ class VehicleMaker { ... - Factory<Tire> F; // Bad -- abbreviation and non-descriptive. - Factory<Tire> Factory; // Better. - Factory<Tire> TireFactory; // Even better -- if VehicleMaker has more than one - // kind of factories. + Factory<Tire> f; // Bad -- abbreviation and non-descriptive. + Factory<Tire> factory; // Better. + Factory<Tire> tireFactory; // Even better -- if VehicleMaker has more than + // one kind of factory. }; - Vehicle makeVehicle(VehicleType Type) { - VehicleMaker M; // Might be OK if having a short life-span. - Tire Tmp1 = M.makeTire(); // Bad -- 'Tmp1' provides no information. - Light Headlight = M.makeLight("head"); // Good -- descriptive. + Vehicle makeVehicle(VehicleType type) { + // Reusing the type name in lowerCamelCase form is often a good way to get + // a suitable variable name. + VehicleMaker vehicleMaker; + + // Bad -- 'tmp1' provides no information. + Tire tmp1 = vehicleMaker.makeTire(); + + // Good -- descriptive. + Light headlight = vehicleMaker.makeLight("head"); ... } Index: llvm/.clang-tidy =================================================================== --- llvm/.clang-tidy +++ llvm/.clang-tidy @@ -7,11 +7,11 @@ - key: readability-identifier-naming.FunctionCase value: camelBack - key: readability-identifier-naming.MemberCase - value: CamelCase + value: camelBack - key: readability-identifier-naming.ParameterCase - value: CamelCase + value: camelBack - key: readability-identifier-naming.UnionCase value: CamelCase - key: readability-identifier-naming.VariableCase - value: CamelCase + value: camelBack Index: clang/.clang-tidy =================================================================== --- clang/.clang-tidy +++ clang/.clang-tidy @@ -12,11 +12,11 @@ - key: readability-identifier-naming.FunctionCase value: camelBack - key: readability-identifier-naming.MemberCase - value: CamelCase + value: camelBack - key: readability-identifier-naming.ParameterCase - value: CamelCase + value: camelBack - key: readability-identifier-naming.UnionCase value: CamelCase - key: readability-identifier-naming.VariableCase - value: CamelCase + value: camelBack Index: .clang-tidy =================================================================== --- .clang-tidy +++ .clang-tidy @@ -7,11 +7,11 @@ - key: readability-identifier-naming.FunctionCase value: camelBack - key: readability-identifier-naming.MemberCase - value: CamelCase + value: camelBack - key: readability-identifier-naming.ParameterCase - value: CamelCase + value: camelBack - key: readability-identifier-naming.UnionCase value: CamelCase - key: readability-identifier-naming.VariableCase - value: CamelCase + value: camelBack
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits