Roadmap › Clean Code, Testing & Best Practices › Module: Readable Code
Lessons in this course (12)
1. Naming
Basic★ Must knowLesson 1 of 12
- Names reveal intent:
daysSinceLastLogin, notdordata2. - Classes = nouns (
InvoiceCalculator); methods = verbs (CalculateTotal,SendReminder). - Booleans read as questions:
isActive,hasAccess,canRetry. - Avoid noise words:
Manager,Processor,Data,Info(unless they really mean something). - .NET conventions:
PascalCasefor types, methods, properties, constants;camelCasefor locals and parameters;_camelCasefor private fields;Iprefix for interfaces;Asyncsuffix for async methods.
csharp
// ❌
public List<int> Get(List<int> l) { var r = new List<int>(); foreach (var x in l) if (x % 2 == 0) r.Add(x); return r; }
// ✅
public IReadOnlyList<int> GetEvenNumbers(IEnumerable<int> numbers) => numbers.Where(n => n % 2 == 0).ToList();