Posts

On 'leaky abstractions'

Recently I was reviewing a pull request, and a rather simple piece of code got my attention as a good example of 'leaky abstractions'. So, let's review it. I removed all specific implementation details and made the sample code very generic while maintaining the 'leaking pattern'. public record Data(int Id, long Value, bool Flag); public IEnumerable<Data> CallingMethodWithLeakingAbstractions() { var input = ProduceInput(); var result = LeakingProcessing(input); result.AddRange(input.Where(x => !x.Flag)); // probably do some other things unrelated to modifying the result return result; } private List<Data> LeakingProcessing(IList<Data> source) { return source .Where(x => x.Flag) .Select(ProcessValue) .ToList(); } private Data ProcessValue(Data input) { ... }; We have a Data record (class) and some processing for it. So, why do I think this sample demonstrates the 'leaky

On AsyncLazy in .NET

Today I saw a post on linkedin on combining Lazy<T> with a Task, and then awaiting on lazy.Value, and if developers should ever use such an approach. A few thoughts came to mind about why we should not , for example, inability to pass a cancellation token in a transparent manner and overall obscurity of applying a strictly non-async pattern to an async operation. But then I thought about how would I implement a real async lazy wrapper. Below is what came out. This is just an idea, though it does look quite usable :) public sealed class AsyncLazy<T> : IDisposable where T : class { private const int MaxSpinWaitCount = 10; private enum Stages { Uninitialized = 0, Producing, Produced } private ManualResetEventSlim? resetEvent = new (false, MaxSpinWaitCount); private readonly Func<CancellationToken, Task<T>> producer; private T value; private int stage = (int)Stages.Uninitialized; public AsyncLazy(Func<CancellationToken, Task<T>> produce

On Serilog 'log enrichment' feature

This brief note is for .NET developers who use Serilog (great tool, by the way!) for logging implementations. I want to cover a very powerful, though rarely spoken of, feature - 'log enrichment'. It is an interesting concept and implementation which they describe as 'log events can be enriched with properties in various ways'. The main idea is that whatever log event gets written, it may be improved with custom data coming from various sources. So, what implementing log enrichers would give and how may it be applied? The first thing to mention is that neither business code, nor application code is designed to produce logs; it has a completely different purpose. The less logging code we have inside our business and application code, the cleaner, less coupled, and more cohesive our code is. Those working with enterprise code are quite used to code 'spiced up' with logging statements. While 'what and when' to log and 'what and when' not to log is a

On developer interview questions

Recently I happened to answer a reporter’s question – “what is your favorite API interview question?” … Right, many of us have passed through multiple interviews on either side and have our own ‘favorites’ and ‘outsiders’. Many, who conducted interviews, have their list of questions or topics they want to have covered during an interview. Well, I have a few such lists. But let’s turn the flow slightly from ‘what we want to ask’ or ‘what answers we want to get’ to ‘what result we want to achieve’. And the result is, quite frankly, that we want to hire a good candidate as fast as possible. Those invited as interviewees are our potential good candidates, we just need to confirm they are really good. So, this becomes the goal of the interview – confirm that the candidate is good. All right, now we have a very practical goal, let’s explore the best way to arrive at it, shall we? Well, I think we should add one more dimension to our task. I think, many realize that an interview is never abou

Introduction, and welcome!

Welcome, dear reader! As you see, this is the very first post on this blog, and neither you nor I have an idea how it will further develop. After a very long time of not blogging or writing, I decided to start again. My old blog and writings are long gone, and they would be of no interest now. So, a fresh start… Just let me introduce myself in slightly more detail than my ‘About’ short note. My name is Dimitry Slabko, I am originally from Russia, from the beautiful city of St. Petersburg. Now I reside in Mexico, in a nice cozy little town San Miguel de Allende. I have been programming since late 90’s, and adopted .NET development since its version 2.0, almost from its release date. I did WinForms, WPF, Silverlight, ASP.NET, WCF, MVC, and even some WebForms. I was very glad to switch to .NET Core, I even thought something along the lines “finally, a properly designed .NET version”. Last quite a few years I have been doing Web, services, and cloud development. Mostly pure backend, pure .