Pure vs Impure Methods: Understanding Side Effects in Coding

What’s the difference between these two methods? and Well, there are two ways of answering this question (aren’t there always?). One way is to look from outside in. If we squint our eyes and only look at the method signatures, they are identical. (The only difference is the name, but that’s just so I can… Continue reading Pure vs Impure Methods: Understanding Side Effects in Coding

Understanding Generics and Covariance in C#

Introduction to Generics in C# Ever hit a wall like this? Yet swap to IEnumerable<Fruit> and it magically works? This trips up devs assuming inheritance flows through generics. It spotlights invariance vs. covariance – List<T> blocks it to prevent bugs, while IEnumerable<out T> enables safe read-only views. Crucial for bulletproof APIs. Core Mechanism Generics like… Continue reading Understanding Generics and Covariance in C#

Mastering Infinite Sequences in C#: A Complete Guide

Introduction to Infinite Sequences Infinite sequences in C# represent data streams that generate values indefinitely on demand, without precomputing or storing everything in memory. They leverage lazy evaluation, where elements are produced only when needed, making them ideal for scenarios like simulations or endless data generation. This approach prevents memory exhaustion from unbounded collections. IEnumerable… Continue reading Mastering Infinite Sequences in C#: A Complete Guide

If You Don’t Want to Be Replaced by a Robot, Don’t Act Like a Robot

Here’s a rant I’ve been sitting on, and it’s time to let it out. In the modern software development landscape, there’s an unsettling trend: we pretend that the perfect project flow is a conveyor belt, and the only thing slowing us down is “imperfect” specification. Every sprint, there are grumbles about user stories that aren’t… Continue reading If You Don’t Want to Be Replaced by a Robot, Don’t Act Like a Robot

Changing Object Types to Reflect State Transitions

In object-oriented design, objects encapsulate state and expose behavior that operates on that state. Consequently, if an object must exhibit different behaviors at various stages of its lifecycle, it can be beneficial to represent these transitions by changing its type. For example, consider a system that manages books. A newly created but unsaved book might… Continue reading Changing Object Types to Reflect State Transitions

The Interface Is Owned by the Client

This one is a less known principle, but with great implications. It is related to the Interface Segregation Principle, as well as to the Dependency Inversion Principle. It also dictates where interfaces should live in a multiple assembly architecture. This is going to be interesting, so hang on to your keyboards. What Do You Mean?… Continue reading The Interface Is Owned by the Client

The Single Responsibility Principle

Definition According to Wikipedia the Single Responsibility Principle is a computer program principle that states that “A module should be responsible to one, and only one, actor”. Robert C. Martin, the originator of the term, expresses the principle as “A class should have only one reason to change”. In my experience as an interviewer, I… Continue reading The Single Responsibility Principle