code quality

Work in Progress

Concept

Readability

  • code needs to be of high quality
  • future developers(and yourself) need to understand and modify it later
GuidelineKey IdeaExample / Implication
Avoid Long MethodsKeep methods short (≈ ≤30 LoC)Smaller methods are easier to understand and debug
Avoid Deep NestingLimit indentation levels (≤3)Use early returns or guard clauses to simplify logic
Avoid Complicated ExpressionsBreak complex logic into stepsUse intermediate variables for clarity
Avoid Magic NumbersReplace literals with named constantsMAX_SIZE is clearer than 10
Make Code ObviousPrefer explicit, clear constructsUse enums instead of numeric states
Structure Code LogicallyOrganize code like a storyGroup related statements with spacing
Don’t “Trip Up” ReaderAvoid confusing or inconsistent patternsNo unused params, no misleading similarities
Practice KISSKeep it simple, stupidAvoid unnecessary complexity or “clever” tricks
Avoid Premature OptimizationOptimize only when necessaryFocus on correctness before performance
SLAP (Single Level of Abstraction)Keep same abstraction level per functionAvoid mixing high-level steps with low-level details
Make Happy Path ProminentHighlight main logic flowUse guard clauses to handle edge cases early

Coding standards

  • follow a consistent style
  • make entire codebase look like its written by one person
  • IDE can help with style

Naming

GuidelineKey IdeaExample / Implication
Use Nouns & Verbs ProperlyNouns for data, verbs for actionscalculateTotal() vs total()
Use Standard WordsAvoid slang, abbreviations, or obscure termsUse clear, common terminology
Use Names to ExplainNames should convey purposeremoveWhitespace() vs process()
Proper Length NamesNot too short, not too longAvoid cryptic abbreviations
Avoid Misleading NamesEnsure consistency and claritySimilar names → similar purposes

Avoid unsafe shortcuts

GuidelineKey IdeaExample / Implication
Use Default BranchHandle all cases explicitlyUse else for true default/error cases
Don’t Recycle VariablesOne variable = one purposeAvoid reusing parameters as locals
Avoid Empty Catch BlocksDon’t ignore errors silentlyAt least log or explain why ignored
Delete Dead CodeRemove unused code promptlyVersion control can recover it if needed
Minimize ScopeLimit variable visibilityPrefer local over global variables
Minimize DuplicationAvoid repeated logic (DRY)Refactor common code into functions

Code comments

GuidelineKey IdeaExample / Implication
Comment Minimally but SufficientlyCode should be mostly self-explanatoryImprove code instead of over-commenting
Don’t Repeat the ObviousAvoid redundant commentsx++ doesn’t need “increment x”
Write for the ReaderComments should help others understandUse clear, professional explanations
Explain WHAT & WHYFocus on intent and rationaleAvoid explaining HOW if code is clear