Variable and function names should clearly communicate their actual purpose and behavior, not just their initial intent. Avoid vague or misleading names that don’t accurately reflect what the code does.
When naming variables and functions, consider:
Example of problematic naming:
// Misleading - suggests it's only used for initialization
const initialValue = getDefaultValue();
// Better - clearly indicates it's used for resets
const defaultValue = getDefaultValue();
// Vague - doesn't explain what data type operation this performs
export const getDataType = (dataType?: string): DataTypes => {
// implementation
}
// Better - specific about the conversion/mapping being performed
const mapStringToDataType = (dataType?: string): DataTypes => {
// implementation
}
Names should serve as documentation for future maintainers, making the code’s intent immediately clear without requiring deep analysis of the implementation.
Enter the URL of a public GitHub repository