Use specific checklists to ensure comprehensive and high-quality code commenting for general code, data declarations, and program structures...
Apply this checklist to ensure overall comment quality:
Apply this checklist when declaring variables, constants, and data structures:
// milliseconds, // kilograms)Apply this checklist for subprograms, functions, classes, and files:
// BAD: No units or range
let timeout = 5000;
// GOOD: Complete documentation
// Timeout in milliseconds for API calls (range: 1000-30000)
let timeout = 5000;
# BAD: Magic number documented but not replaced
# Days in a year (365)
days = 365
# GOOD: Named constant
DAYS_IN_YEAR = 365
days = DAYS_IN_YEAR
// BAD: Global used without identification
public static int count;
// ... later ...
count++;
// GOOD: Clearly identified at usage
public static int g_userCount; // Global: total active users
// ... later ...
g_userCount++; // Global: increment active user count
// BAD: Complex structure without comment
for (let i = 0; i < items.length; i++) {
for (let j = i + 1; j < items.length; j++) {
if (items[i] > items[j]) {
// swap
}
}
}
// GOOD: Commented or simplified
// Bubble sort: compare each pair and swap if out of order
for (let i = 0; i < items.length; i++) {
for (let j = i + 1; j < items.length; j++) {
if (items[i] > items[j]) {
swap(items, i, j);
}
}
}