Appendix B
Code Review Checklist
Print this page and keep it next to your keyboard during code reviews. Every item comes from a recipe in this book and from a problem I found in real systems more than once.
Data access
- Every SQL value is a parameter. No user input is concatenated into SQL text.
- Every connection, command and reader is disposed (
usingorawait using). - Queries name their columns. No
SELECT *in application code. - Bulk work uses
SqlBulkCopyor table-valued parameters, not a loop of single inserts. - Multi-statement changes run in a transaction, and the transaction scope is as short as possible.
SQL Server
- Procedures start with
SET NOCOUNT ONand useTRY...CATCHwithTHROW. - No cursors where a set-based statement will do.
- No
NOLOCKhints added "for performance". - Paging uses
OFFSET ... FETCHwith a deterministicORDER BY. - Dynamic SQL uses
sp_executesqlwith parameters andQUOTENAMEfor identifiers.
Errors and logging
- No empty
catchblocks. Everycatcheither handles the error, adds context and rethrows, or logs at a boundary. - Rethrow with
throw;, neverthrow ex;. - Log messages use templates with named values, not string concatenation.
- Logs never contain passwords, tokens, full card numbers or personal data that isn't needed.
- Every request or job run has a correlation ID in its log entries.
Configuration and security
- No connection strings, passwords or keys in source code or committed config files.
- Settings are bound to typed options and validated at startup.
- Passwords are hashed with PBKDF2 (or the Identity hasher), never MD5, SHA1 or plain SHA-256.
- Encryption uses
AesGcmwith a fresh nonce; keys come from a secret store. - Tokens come from
RandomNumberGenerator, and secrets are compared withCryptographicOperations.FixedTimeEquals. - File paths built from input are resolved and checked against an allowed root.
Integration
HttpClientcomes fromIHttpClientFactory, with explicit timeouts and a resilience policy.- E-mail goes through MailKit, with a plain-text alternative, and failures are retried or queued.
- Files are written to a temporary name and then moved into place.
- CSV output quotes fields that contain separators, quotes or line breaks, and states its encoding.
Background work
- No
Thread.Sleeploops. Timers usePeriodicTimerand honor cancellation. - Services shut down gracefully: they stop taking new work and finish or checkpoint current work.
- One failing item doesn't stop the whole batch, and failures are visible in the logs.
Everyday code
- Times are stored in UTC (or as
DateTimeOffset) and converted to local time only for display. - No
ArrayListorHashtablein new code. - Helper classes are small and focused. Nothing new goes into
Utility.cs. - Generated files are not edited by hand, and dead files are deleted, not left in the project folder.
- The change compiles without new warnings.