domains / app-frameworks / 30-seconds/30-seconds-of-code
Consistent, Clear Identifiers
Use naming that is consistent with the surrounding code/style, avoids ambiguity, and preserves semantic meaning—both in code and in documentation. Rules:
Use naming that is consistent with the surrounding code/style, avoids ambiguity, and preserves semantic meaning—both in code and in documentation.
Rules:
- Match the existing naming convention (e.g., Python snippet uses lowercase variable names):
- Prefer
sumoverSumwhen the rest issnake_case/lowercase.
- Prefer
- Avoid shadowing/ambiguity:
- Don’t use the same identifier for a collection and the iterated element.
- Example:
a.forEach((value) => { magnitudeOfA += value ** 2; });
- Prefer readability over excessive abbreviation:
- Use clearer names like
lengthinstead of vague short forms.
- Use clearer names like
- When transforming casing (title case, etc.), don’t destroy internal capital patterns (e.g.,
mcDolansshould not becomeMcdolans). - When referencing built-ins in text/docs, use canonical API names:
- Use
Array.prototype.map()(not justmap()).
- Use