Function and method names should precisely describe their purpose and behavior. Choose names that explicitly communicate what the function does, including any special conditions or behaviors.
Function and method names should precisely describe their purpose and behavior. Choose names that explicitly communicate what the function does, including any special conditions or behaviors.
Key guidelines:
toJSON()
instead of toJson()
for JSON serialization)setupBindings()
over setupInstance()
when setting up bindings rather than an instance)maybeEmitDeprecationWarning
or emitDeprecationWarningIfAlgoIsShake
instead of just emitDeprecationWarning
)enable()
/disable()
if that’s the established pattern for similar functionality)Example:
// ❌ Poor naming - ambiguous about purpose and behavior
function setup(instance, memory) {
// Implementation
}
// ✅ Better naming - clearly describes what's being set up
function setupBindings(instance, { memory = instance.exports.memory } = {}) {
// Implementation
}
// ❌ Poor naming - doesn't indicate conditional behavior
const emitDeprecationWarning = getDeprecationWarningEmitter();
// ✅ Better naming - indicates the warning is conditional
const maybeEmitDeprecationWarning = getDeprecationWarningEmitter();
Enter the URL of a public GitHub repository