Replies: 1 comment 2 replies
-
|
Will we change existing code to conform to this? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This discussion aims to discuss and decide upon a naming convention for eld. Currently, we do not have a consistent naming convention. Consistent naming convention helps make the code more readable. The primary goals for naming convention for eld are:
Current LLVM naming convention:
4.1) Enum should have Kind-like suffix if the enum is used as a discriminator. For example: ValueKind
4.2) Unscoped enumerators should be prefixed with the enum name / abbreviation.
Functions and classes that are like STL should follow C++ naming convention. (That is, snake_case for almost everything)
Trying to completely follow LLVM naming convention has been difficult. Let's look at some of the reasons:
The same naming convention for type and variable names poses unnecessary difficulties. For example, we had a
type
GeneralOptions::AddressMapand corresponding memberGeneralOptions::m_AddressMap. With thesame naming convention, the natural name for both the type and the variable would be
AddressMap-- naming conflict.There are many more such examples.
Similar problem happens with parameter and member names in setter-functions.
PascalCase for variable names seems a bit off for some cases, such as:
There are a few ways to solve these issues. One way is to use abbreviations for the variable name.
For example, a variable declaration can be
AddressMap AM. While this is good for well-known typessuch as
Module,LinkerConfigand some others, it can make the code less-readable if used for less-knowntypes such as
AddressMap. One of the LLVM guidelines even mentions:There have been discussions in LLVM community to change the naming convention for the variable names:
Variable Names Plan — LLVM 21.0.0git documentation,
RFC: changing variable naming rules in LLVM codebase - Project Infrastructure / LLVM Dev List Archives - LLVM Discussion Forums.
A lot of people are in support of changing the naming convention for variable as the current pattern of
Triple TheTripleis a bit redundant.However, it seems that the variable name change plan did not have enough momentum to go through, in particular,
there were concerns regarding git-blame usability.
Given the LLVM community interest in moving away from PascalCase for variable names, I think we should not proceed
with PascalCase for eld, especially because it is already posing difficulties in adoption.
In the RFC, there are supporters of both camelCase and snake_case for variable names, but it seems that camelCase is more favorable. Some people even mentioned
m_prefix for private/protected members.I think we can directly follow LLVM naming convention in all cases except the variable names.
I propose the following rules for the eld naming conventions:
MforModule,LCforLinkerConfigand so on.4.1) Enum should have Kind-like suffix if the enum is used as a discriminator. For example: ValueKind
4.2) Unscoped enumerators should be prefixed with the enum name / abbreviation.
Functions and classes that are like STL should follow C++ naming convention. (That is, snake_case for almost everything)
Please let me know if you have any comments.
If these conventions are okay with everyone, then can we should start enforcing them for the new code that we add.
Beta Was this translation helpful? Give feedback.
All reactions