#coding-practices
32 articles tagged with #coding-practices
How to unit test Entity Framework Core?
Unit test code that uses Entity Framework Core with test doubles for DbContext and DbSet, so the tests stay fast and focused on the system under test.
Secure coding basics - OWASP Top 10 (2017) for .NET developers
OWASP Top 10 2017 risks are translated into practical .NET safeguards for injection, authentication, access control, XSS, deserialization, dependencies and logging.
Resilient HTTP calls with Polly - retry, timeout and circuit breaker
Polly 5.x adds retry, timeout and circuit breaker policies around HTTP calls, with guidance on composition, transient failures, idempotency and safe handling of writes.
Structured logging with Serilog - why plain text logs are not enough
Structured logging with Serilog replaces ambiguous text with searchable properties, consistent message templates, correlation context and safer ASP.NET Core operations.
How to test ASP.NET Core Web API with in-memory TestServer?
This guide tests an ASP.NET Core Web API with an in-memory TestServer, covering host setup, HTTP requests, dependency boundaries and fast feedback without a deployed service.
Integration tests vs unit tests - where to draw the line
Unit and integration tests serve different boundaries, feedback loops and maintenance costs, with practical guidance for choosing test types and organising a .NET solution.
Remove dead code - why and how to find it safely
Dead code increases cognitive load and deployment risk, so this guide explains how to find candidates, confirm they are unused and remove them safely with history as a backup.
Avoid sequential coupling and circular dependencies - with examples
Sequential coupling and circular dependencies create hidden constraints, so constructor injection, builders, interfaces and events make code easier to test, change and evolve.
TypeScript for C# developers - Part 1
TypeScript for C# developers introduces types, interfaces, classes, enums, lambdas, null checks, compilation and familiar concepts from C# development for practical guidance.
Static code analysis with StyleCop, FxCop and ReSharper
Static code analysis explained through StyleCop, FxCop, ReSharper, rule sets, IDE checks, local builds, CI integration and gradual warning reduction.
Git branching strategies - Git Flow vs GitHub Flow
Git Flow and GitHub Flow compared through branch roles, pull requests, release stabilisation, hotfixes, continuous delivery and team selection criteria.
Semantic versioning for NuGet packages and APIs
Semantic versioning explained through major, minor and patch changes, pre-release labels, package compatibility, API versions and communication with consumers for practical guidance.
Feature toggles - shipping unfinished code safely
Feature toggles explained through release control, toggle types, configuration, rollout, cleanup and practices for shipping unfinished code without accumulating debt.
Logging best practices - what to log, what not to log
Logging best practices explained through operational value, useful fields, sensitive data, correlation, structured logging, retention and practical logging pipelines for practical guidance.
How to write maintainable LINQ and Entity Framework queries?
Maintainable LINQ and Entity Framework queries explained through in-memory filtering, N+1 queries, projection, tracking and practices for readable query code.
Defensive coding - guard clauses and null checks without the noise
Defensive coding explained through guard clauses, boundary validation, specific exceptions, null checks, empty collections and clearer .NET application logic for practical guidance.
Test Driven Development (TDD) - is it worth it for our team
Test-Driven Development evaluated through its design benefits, upfront costs, defect feedback, suitable code areas and a gradual adoption approach for teams.
What is a Test Double - stub vs mock vs fake
Test doubles explained through dummy, stub, spy, mock and fake objects, with practical examples showing when stubs, mocks and fakes are appropriate.
Unit Test Best Practices - FIRST properties
FIRST properties explained through fast, independent, repeatable, self-validating and timely unit tests, with practical guidance for keeping a test suite healthy.
Async and await in C# - common mistakes
Async and await explained for web applications, including I/O-bound work, async void, blocking calls, deadlocks, ConfigureAwait, fake async, and sequential awaits.
How to do TDD (Test-Driven Development)?
Test-Driven Development explained through the Red-Green-Refactor cycle and a step-by-step fund-universe example built with tests first for practical development and design.
What is technical debt and how to manage it?
Technical debt explained through its causes, principal, compound interest, visibility, prioritisation, repayment practices, and engineering habits that prevent new debt.
What is engineering practices and why do we need them?
Engineering practices explained as shared disciplines for building, testing, delivering, and operating software with consistent quality, faster feedback, and safer releases.
Exception handling best practices in .NET
Exception handling practices for .NET, ASP.NET MVC, and Web API covering swallowed exceptions, stack traces, specific catches, and global error handling.
Code review checklist for .NET teams
A practical .NET code review checklist covering design, readability, correctness, errors, security, performance, testing, operations, and constructive review comments and discussion.
How to write unit tests with NUnit and Moq?
Unit testing with NUnit and Moq explained through FIRST properties, the AAA pattern, test doubles, test cases, exceptions, and verification of interactions.
What is a God object and how to break it?
God objects explained through their warning signs, causes, and a step-by-step refactoring approach using characterization tests, extraction, interfaces, and dependency injection.
Why we must not use magic numbers and hard-coding?
Magic numbers and hard-coded values explained with their maintenance and security risks, plus practical replacements using constants, enums, configuration, and read-only values.
How to use Dependency Injection with an IoC container in ASP.NET MVC?
Dependency Injection and IoC containers explained through Unity and Autofac setup in ASP.NET MVC 5, including object lifetimes and practical container wiring.
SOLID Principles - Part 2
The remaining SOLID principles, Liskov Substitution, Interface Segregation and Dependency Inversion, explained with practical examples from a fund domain and practical guidance.
SOLID Principles - Part 1
The first two SOLID principles, Single Responsibility and Open/Closed, explained with fund report and fee calculation examples in C#, plus when not to apply them.
Why we need Clean Code?
Why clean code matters, what makes code clean (meaningful names, small functions, guard clauses, comments that explain why) and how to bring the practice into your team.