IC Improve Code Recipes

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 (using or await using).
  • Queries name their columns. No SELECT * in application code.
  • Bulk work uses SqlBulkCopy or 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 ON and use TRY...CATCH with THROW.
  • No cursors where a set-based statement will do.
  • No NOLOCK hints added "for performance".
  • Paging uses OFFSET ... FETCH with a deterministic ORDER BY.
  • Dynamic SQL uses sp_executesql with parameters and QUOTENAME for identifiers.

Errors and logging

  • No empty catch blocks. Every catch either handles the error, adds context and rethrows, or logs at a boundary.
  • Rethrow with throw;, never throw 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 AesGcm with a fresh nonce; keys come from a secret store.
  • Tokens come from RandomNumberGenerator, and secrets are compared with CryptographicOperations.FixedTimeEquals.
  • File paths built from input are resolved and checked against an allowed root.

Integration

  • HttpClient comes from IHttpClientFactory, 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.Sleep loops. Timers use PeriodicTimer and 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 ArrayList or Hashtable in 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.