MetaPost 2024-04-24
Stephen Cleary
by
1d ago
I don’t do meta-posts that often, but this is one. Feel free to skip this if you don’t care! :D ICYMI (In Case You Missed It) I’m planning to write several rather small blog posts that will mostly be pointers to other things. I’ve been publishing more GitHub repositories, Gists, and other things (occasional videos and podcasts). It has occurred to me recently that most of my followers are not aware of these; I apologize, and I’ll try to be better about publishing a note here about them. These blog posts will have an ICYMI prefix. Unless I forget. Advertisements On a completely different note ..read more
Visit website
C# Advent: The Joy of Immutable Update Patterns
Stephen Cleary
by
4M ago
This is my first-ever post that is part of C# Advent organized by @mgroves. This year there’s a video, too, including yours-truly singing while wearing my favorite Christmas shirt! Joy to the World! Glory to God in the highest, and on earth peace, good will toward men. Luke 2:14 I love Christmas! It’s easily my favorite holiday. In spite of difficulties and upheaval in the world (it is 2023 right now), Christmas still stands as a time of refection and remembrance and expectation. I do approach Christmas from a Christian perspective, and I enjoy meditating on Jesus’ birth during this time. In ..read more
Visit website
ConfigureAwait in .NET 8
Stephen Cleary
by
6M ago
I don’t often write “what’s new in .NET” posts, but .NET 8.0 has an interesting addition that I haven’t seen a lot of people talk about. ConfigureAwait is getting a pretty good overhaul/enhancement; let’s take a look! ConfigureAwait(true) and ConfigureAwait(false) First, let’s review the semantics and history of the original ConfigureAwait, which takes a boolean argument named continueOnCapturedContext. When await acts on a task (Task, Task<T>, ValueTask, or ValueTask<T>), its default behavior is to capture a “context”; later, when the task completes, the async method resumes execu ..read more
Visit website
Padding for Overlaid Structs
Stephen Cleary
by
7M ago
Last time we covered the basics of memory-mapped files and how to overlay structs onto the in-memory view of the file. This time we’ll take a look at different techniques to add “padding” or “holes” in our overlaid structs. Sometimes your overlaid struct is a header or container for another struct, which may be one of several different structure types. For example, a binary file may be composed of records, each with an identical header, and one field of that header is the record type, which defines how the remainder of that record should be interpreted. For this post, we’ll use the same Data s ..read more
Visit website
Memory-Mapped Files and Overlaid Structs
Stephen Cleary
by
7M ago
It has been a long, long time since I’ve used memory-mapped files - I think the last time was before .NET existed (!). Recently, I had a need to work with memory-mapped files in C#, and I gathered together a few resources that explain how to do it - specifically, how to map a file into memory and then “overlay” a structure on top of that memory. Since it took me a while to figure this out (and I learned about some cool upcoming features along the way), I thought I’d write this up into a proper post or two. Memory-Mapped Files Memory-mapped files are a pretty cool technique, where instead of re ..read more
Visit website
Grounded ChatGPT
Stephen Cleary
by
8M ago
So, there’s this thing you may have heard of called ChatGPT. A lot of people (myself included) have thought “OK, nice toy. It’s pretty good at producing human-sounding text. But I want to run it on my own data without becoming a data scientist and spending a few hundred thousand dollars in training costs.” Then someone pointed out to me there’s already a technique for this called Retrieval Augmented Generation, and in fact there’s some sample code right there showing how to do it. Retrieval Augmented Generation To save you a Google search (or ChatGPT query?), here’s my super-simple description ..read more
Visit website
Cancellation, Part 1: Overview
Stephen Cleary
by
8M ago
Cancellation is a topic that I haven’t written on much yet, because the Microsoft documentation is quite good. But after answering many questions for many years, I thought it would be a good topic to cover once, exhaustively. Cooperative Cancellation Cancellation in .NET is cooperative. What this really means is that one part of the code Requests cancellation, and another part of the code Responds to that request. We often talk about some code “cancelling” other code, but what actually happens is that the requesting code just politely notifies the other code that it would like it to please sto ..read more
Visit website
Modern C# Techniques, Part 3: Generic Code Generation
Stephen Cleary
by
8M ago
This technique really excites me! We’re in for a good ride today… C++ Templates and Code Generation Before we take a look at C# generics, first I’ll take a brief look at how C++ templates are used for code generation. Templates (and generics) are both forms of polymorphic functions; that is, you define one type (or method) that takes a type parameter, and the generic type/method is able to change its behavior based on the type passed in. C++ templates are purely a compile-time construct; they instruct the compiler how to generate the code for the template type/method. Specifically, the compile ..read more
Visit website
Modern C# Techniques, Part 2: Value Records
Stephen Cleary
by
8M ago
Today I’ll cover another technique for modern C# that isn’t exactly new, but which the language supports much better than it used to. I’m calling today’s technique Value Records, which are a form of the more general “value object” pattern that is specific to modern C#. But before we dive into the solution, let’s look at the problem. Primitive Obsession The name of the antipattern we’re trying to remove is Primitive Obsession. This is a highly searchable term with some great descriptions out there. Essentially, Primitive Obsession is when a developer (over)uses primitives (string, int, Guid, de ..read more
Visit website
Asynchronous Messaging, Part 4: Retrieve Results
Stephen Cleary
by
8M ago
So far in this series, we’ve covered how asynchronous messaging can be implemented with a durable queue and a backend service. Those are the most necessary components of the solution, but another piece is sometimes necessary. Many times, it’s the desire to “return early” or “fire and forget” that start developers down the path of exogenous code and asynchronous messaging. Sometimes the client, as the originator of the request, wants to get the results of the long-running background operation. No Results Necessary Before looking into delivering results, it’s important to note that there are man ..read more
Visit website

Follow Stephen Cleary on FeedSpot

Continue with Google
Continue with Apple
OR