.NET R&D Digest (August, 2021)

The summer is over, the sun isn’t shining as bright as a month ago. What does it mean? It means we will have more time to read something interesting – like a new issue of .NET R&D Digest which is by a fair coincidence is … here!

This issue includes a bits of story, software development, .NET, security, diagnostics, performance and computer science.

Enjoy!

Life & Story

  1. Patterns in confusing explanations (by Julia Evans)
    Explaining thing is hard, writing explanations are even harder (if you don’t believe me I highly recommend you to try because it is an amazing experience of literally, feeling like you can’t put your thoughts on paper). Because of that it is common to make mistakes when explaining things. In this post Julia Evans shares a set of patterns which if you follow them can confuse your readers. But don’t panic each pattern is accompanied by an example of how you can avoid it and make your explanation simpler and friendly.
  2. Adventures in mTLS Debugging (by Travis Illig)
    Modern platforms are complex. On the one side they simplify things allowing us to spin up a cluster with a few commands but on the other, especially in case of internal issues, it can a big challenge to even understand the what is going wrong. In this post Travis Illig shares his adventure about updating system components to a newer version and what unexpected problems it caused. The huge take from the story is to never give up and keep digging.

Computer Science

  1. Time, Clocks, and the Ordering of Events in a Distributed System (by Leslie Lamport)
    Distributed systems is naturally complex. Besides simple “having multiple parts means more things can go wrong” there are some issue which are important to handle properly. One of such things is a proper ordering of events (to preserve causality). Turns out you can’t use system clock for this 🙂 In this paper from 70s Leslie Lamport describes a solution to this problem by implementing a logical clock. Nowadays logical clock is something you can easily find in almost any distributed system, so it is interesting to see where these things came from. You can also find more information about logical clocks in Lamport Clock pattern in patterns of distributed systems by Unmesh Joshi.

Software Development

  1. Gateway (by Martin Fowler)
    A lot of software design pattern seem similar i.e. facade and adapter, decorator and proxy and so on. However despite they look that way in code they have significant differences in purpose. In this post Martin Fowler describes a «Gateway» pattern, which can be used to separate application code, domain and logic from external services in a way to simplify usage and prevent unnecessary external concepts to flow into our application vocabulary.
  2. Conversation about skills and learning (by Aditya Mandaleeka, Elinor Fung, Jeremy Kuhne, Jose Perez Rodriguez, Kunal Pathak, Maoni Stephens, Maryam Ariyan, Rainer Sigwald, Tanner Gooding, Thays Grazia and Rich Lander)
    What skills do you need to be a good software engineer? Do you need to know ASM or C? Do you need to spend all your free time to learn new things? These aren’t easy questions. In this conversation blog post Aditya Mandaleeka, Elinor Fung, Jeremy Kuhne, Jose Perez Rodriguez, Kunal Pathak, Maoni Stephens, Maryam Ariyan, Rainer Sigwald, Tanner Gooding, Thays Grazia and Rich Lander from .NET team describe how they got into .NET team, what skill do they use every day and how they learn new things and stay current. 
  3. When stateless services are useless (by Szymon Kulec)
    It is a common modern rule that all services should be stateless because it is so much easier to develop and operate a stateless service. I won’t argue that in many cases it is true but at the same time we have a lot of ways to write amazing state full service (ex. using Service Fabric). In this post Szymon Kulec argues that all service must be stateless (and I agree they shouldn’t be) and shares a list of circumstances where a stateless service is not need and can be a burden rather than a solution.

.NET

  1. Performance Improvements in .NET 6 (by Stephen Toub)
    Every release of .NET includes a set of performance improvements and every year Stephen Toub writes a performance improvements blog post to highlight them. This year isn’t exception however this time the list of improvements is so huge that I it will take a separate blog post just to enumerate them! So instead, I would say that in this blog post Stephen Toub shares and demonstrates a tremendous list of performance improvements done in .NET 6 which affect – JIT, GC, networking, array buffers, cryptography, system types, IO, streams and a lot more areas of .NET. Prepare yourself, the blog post is huge but it worth every minute to read it.
  2. Understanding the cost of C# delegates (by Paulo Morgado)
    How hard is to instantiate a delegate? Well, it is not hard at all – you just write a lambda and everything works smoothly. At least it looks that way until you find out the cost of “writing a lambda”. In this post Paulo Morgado share a short history of delegates and describes what is hidden underneath and how we can use this knowledge to make educated decisions when using delegates.
  3. Reducing allocations by caching with StringBuilderCache (by Andrew Lock)
    Have you heard about StringBuilderCache? I didn’t, and there is a reason for that – it is an internal class used across .NET to reduce allocations in common cases. In this post Andrew Lock describes how StringBuilderCache works and demonstrates how it can be used to reduce allocations in small sized string operations.
  4. ValueStringBuilder: a stack-based string-builder (by Andrew Lock)
    Have you ever heard a phrase “you can’t do better than it is already done by a framework”? In many cases it isn’t true – frameworks are written by people, so you can write better but sometimes it isn’t so obvious because framework can use internal types and specific tricks which aren’t accessible to developers. In this post Andrew Lock describes an internal class – ValueStringBuilder which is used by .NET classes to even more reduce allocations (compared to using StringBuilder and StringBuilderCache). The post covers all basic mechanics behind the class allocation model and includes links to source code (for future investigations) and detailed code snippets for the most important parts.
  5. Package Validation (by Anirudh Agnihotry)
    Being a library author isn’t only about fixing bugs and introducing new features. It is also about maintaining compatibility with previous versions because well, time flies and sometimes library users can’t keep up to the latest and greatest. Making sure you package is compatible with new and old platforms and ensuring it doesn’t introduce accidental breaking change is critical but requires a lot of effort. In this post Anirudh Agnihotry describes a new feature available through MSBuild – a package validation, which automatically checks binary and API compatibility between platforms as part of the build process. 
  6. Start a journey into the .NET Profiling APIs (by Christophe Nasarre)
    Writing a profiler is a challenging task. It requires a deep understanding of how target platform operates, what information it exposes and how to integrate with it. In this series Christophe Nasarre demonstrates how you can write and debug your own managed profile. To do this he uses official samples, well written examples and videos. This isn’t a simple journey but it will definitely lead you to a working profile, but not as fast as Pavel Yosifovich did on the DotNext conference 🙂
  7. Conversation about diagnostics (by David Mason, John Salem, Mike McLaughlin, Noah Falk, Sourabh Shirhatti, Tom McDonald and Rich Lander)
    What is diagnostics? What is observability? How do these terms reflect in .NET? Are there any changes in .NET diagnostics? In this conversational post David Mason, John Salem, Mike McLaughlin, Noah Falk, Sourabh Shirhatti, Tom McDonald and Rich Lander from .NET runtime team talk about definitions of above mentioned terms and discuss what .NET runtime has, what have been changed and what can be expected to be introduced or improved in the future versions of .NET.
  8. Caching Enum.ToString to improve performance (by Gérald Barré)
    Every object in .NET has a ToString method. However default implementation performs differently for objects, structure and enums. In this post Gérald Barré demonstrates and benchmarks four methods of how you can speed up Enum.ToString operation. In addition to the post he shares a source generators which may implement this optimisation for you.
  9. Context passing patterns (by Szymon Kulec)
    What are the ways to pass a context to a method? (i.e. dependencies or additional arguments)? In modern applications we tend to use dependency injection containers for that but there are more ways of doing it. In this post Szymon Kulec describes four handy ways of how to pass the context to methods. Each method is accompanied with a small and neat code sample.

Watch & Learn

  1. Honeytokens: Detecting Attacks to Your Web Apps Using Decoys and Deception (by Dana Epp)
    Usually when you hear about security it is all about how to protect your application – sanitise and validate input, use allow and block lists, vulnerabilities and package management but what if I would say that security could be also about leaving a trap? In this video Dana Epp describes «honeytokens» a way to identify malicious intents and make attacker’s life a lot harder.

Tips & Tricks

  1. How to measure elapsed time without allocating a Stopwatch (by Gérald Barré)
    Is there a way to measure execution time without creating stopwatch instance? Indeed there is. In this short tip Gérald Barré demonstrates how you can create a simple ValueType to measure elapsed time.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s