Blog
Posts and series that take software and IT from the basics to advanced topics: from programming languages and databases to architecture and AI.
Classes in Clean Code: Small Classes, Cohesion and Organizing for Change
A class's size is measured by the number of actors who ask it to change, not by lines; methods that share no fields and CA1822 "make it static" warnings signal low cohesion. In the legacy OrderService two price calculations in the same class had drifted apart, quoting 731.50 TRY and charging 690.52 TRY; we gather pricing into a single OrderPricing class and build modern C# classes with primary constructors, sealed and required.
Boundaries: Wrapping Third-Party Code and Learning Tests
Put code you don't control, such as a payment SDK, an email library and a cache, behind an interface shaped by your own need and a single adapter; don't let its types and exceptions leak in. Pin the library's behavior down with learning tests: MimeKit's TryParse even accepts "ada", and on the upgrade from 4.17.0 to 4.18.2 all 13 tests passed unchanged while a transitive security warning disappeared.
Error Handling in Clean Code: Exceptions, the Try Pattern and the Result Pattern
Use the Try pattern or Result<T> for expected business outcomes (out of stock, invalid coupon, payment declined), argument exceptions for bugs and exceptions with added context for infrastructure failures, and catch them only at the application's boundary. We clean up the return codes, the static LastError and the empty catch blocks of the legacy OrderService with these three tools; in our measurement a thrown exception is about 1,165 times slower than TryParse.
Objects or Data Structures? Records, DTOs and Primitive Obsession
An object hides its data and exposes behavior, a data structure exposes data and carries no behavior, and the hybrid in between is the most expensive of all. Use records for DTOs, encapsulation for the domain and value objects such as Money and Email for concepts carried in strings and decimals; we also give a short introduction to the Law of Demeter.
Formatting and File Layout: Making Code Read Like a Newspaper
Formatting is communication, not aesthetics, and a tool rather than a person should enforce it: wrong indentation in a brace-less if makes the log say an e-mail was sent when it wasn't, and SonarAnalyzer and dotnet format catch it, not the compiler. The post covers the newspaper metaphor, vertical layout, member order, one type per file, converting to file-scoped namespaces and splitting a 259-character LINQ chain into lines, with real output.
Comments in Clean Code: When to Write Them and When to Turn Them into Code
Put in code what code can say (names, constants, enums, methods) and in a comment what it can't (why, warnings, external context, a public API's contract): most comments in the legacy OrderService repeat the code, two of them lie, and changelogs and commented-out code belong in Git. The post shows how XML doc comments are checked through CS1572/CS1573/CS1574/CS1591 and covers Ousterhout's case for interface comments, with real output.
Functions in Clean Code: Small Methods, One Level of Abstraction and Guard Clauses
A method should do one thing and stay at one level of abstraction: splitting the 136-line ProcessData in the legacy OrderService with guard clauses, the stepdown rule, a parameter object and CQS takes its Cognitive Complexity from 92 to pieces scoring at most 5, with identical behavior. The post also covers flag arguments, returning records instead of out parameters, guard helpers such as ThrowIfNull and the cost of over-splitting, with real output.
Naming in Clean Code: Intention-Revealing Names, .NET Guidelines and Mixed Turkish-English Names
A good name answers the questions a reader would otherwise ask the code: replacing d, tmp2, k and int t in the legacy OrderService with domain names and constants makes the pricing readable without changing behavior (same totals in five scenarios). The post covers .NET naming rules, Hungarian notation, mixed Turkish-English names and the Turkish I trap that turns Id into ıd under tr-TR, with real output.
What Is Clean Code? Readability, Cost of Change and the 2025 Second Edition
Clean code is code that works and is also cheap to read and change: in Bookstore's legacy OrderService the same cart yields four different totals because of the Turkish I trap, a drifted copy of the pricing logic and DateTime.Now. The 2025 second edition rewrote the book into Code, Design, Architecture and Craftsmanship parts; this series cleans the 609-line file step by step.
Critiquing the Principles: CUPID, Over-Engineering and Where SOLID Really Pays Off
SOLID's value depends on context: in multi-team, long-lived, frequently changing code it lowers the cost of change, while in scripts, prototypes and small CRUD apps it often just adds layers. The measured cost of adding a push channel to minimal, balanced and excessive designs of the same notification feature, Dan North's CUPID proposal and Ousterhout's deep module warning.
Component Principles: Splitting a .NET Solution into Projects (REP, CCP, CRP, ADP, SDP, SAP)
When splitting a solution into projects, classes that change together belong in the same project, dependencies must be acyclic and flow toward stability, and stable projects should be abstract. Measuring the cost of a Common project everyone depends on, computing instability and abstractness on a real solution, and reading the main sequence correctly.
Lesser-Known Principles: Separation of Concerns, Least Astonishment, Fail Fast, CQS and GRASP
The principles outside SOLID drive most everyday decisions: Fail Fast catches errors at startup, CQS keeps a question from changing the answer, and GRASP asks which class a responsibility belongs to. Catching a configuration typo with options validation, the Math.Round surprise, side effects in getters, Explicit Dependencies, Persistence Ignorance and deciding when principles collide.