TaskCompletionSource Pitfalls
ZpqrtBnk
by
1y ago
Imagine you are implementing a client for a server that performs an operation on some data, and that operation is totally asynchronous, and the server has only one connection to it. Contrary to an HTTP server, where a new connection is opened for each request (or, where requests are queued on one connection), requests must be pushed to the server with some sort of unique identifier, and the server will push responses back in whatever order it produces them. Let us try to implement the client API: public async Task<Response> SubmitRequestAsync(Request request) { await server.SendRequ ..read more
Visit website
Tales of FPGA - Road to SDRAM - E02
ZpqrtBnk
by
1y ago
This post is the second one of a serie which starts with Episode 1, in which we have presented what FPGA are, how to control them, and implicitly discovered their major benefit: they make the physical world rational and clean. Indeed, the physical world a.k.a. "reality" is notoriously messy, as anyone who has tried to implement some design with discrete electronic components knows. For instance, should we decide that "zero" is +0V and "one" is +5V... there are chances that the transistor-based AND gate that we carefully assembled on our breadboard outputs +4.8V for "one" and not +5V because, i ..read more
Visit website
Tales of FPGA - Road to SDRAM - E01
ZpqrtBnk
by
1y ago
This post is the first one of a serie, which aims at providing a simple working example of a design that can reliably access the SDRAM chip on a Digilent Arty S7 FPGA development board. Indeed, although this board has been out for quite some time now, such a design seems practically impossible to find on the 'net, for reasons we will try to analyze. I also mean this serie to be an introduction to FPGA for people who have little idea what they actually are nor how they work. So, even if you do not care about accessing SDRAM on that particular board, you may find it an interesting read. In fact ..read more
Visit website
IAsyncDisposable Pitfalls
ZpqrtBnk
by
1y ago
The .NET ecosystem comes with more and more sophisticated Roslyn Analyzers which may seem annoying but actually are quite useful at improving our code and detecting hidden and tricky issues. Say we have a Method method that uses a thing object, which implements IAsyncDisposable and is produced by an async GetAsyncDisposableAsync method. We know about the await using pattern, which guarantees that the object will be async-disposed when the method exits. We have learned that we need to use ConfigureAwait on awaited tasks (else, we get the CA2007: Do not directly await a Task warning). And so, we ..read more
Visit website
The Curse of NULL
ZpqrtBnk
by
1y ago
C# has two main categories of types: value types and reference types. A variable of a value type contains an instance of the type, while a variable of a reference type contains a reference to an instance of the type. In a very non-technical way, one could say that a value type variable is the "thing" itself, while a reference type variable points to the "thing". An integer, for instance, is a value type. An integer variable contains the value itself. It has to be a valid integer value (in the int.MinValue to int.MaxValue range), and is zero by default. And technically, anything that can fit in ..read more
Visit website
CSharp FIXME Code Comments
ZpqrtBnk
by
1y ago
When working on code, I sometime can get deep in "the zone", a creative state where ideas keep flowing and I start refactoring things all around the code base, making quick and dirty changes here and there just to be able to go where I know I want to go. This is accumulating technical debt, and as with any debt, I believe that it can be a good thing, as long as it lets me achieve my goal and there is a reliable plan to repay that debt eventually. Part of that process requires that that debt can be made highly visible. I love to drop "FIXME comments" in my code for that purpose. public void My ..read more
Visit website
Optimizing CSharp Null-Coalescing Operator
ZpqrtBnk
by
1y ago
Consider the following code: public Func<int> F { get; set; } private int GetValue() { // return the value produced by F, // if F is not null, else zero } I naïvely implemented the function as: if (F == null) return default; return F(); Does the job. Elegant Code Yet, ReSharper squiggled the if statement, suggesting I might want to convert to: return F == null ? default : F(); Which is nice indeed. Ah, ReSharper now squiggles the == null statement, suggesting I merge the conditional expression into: return F?.Invoke() ?? default; And... I started to wonder. It certainl ..read more
Visit website
Optimizing CSharp Value Types
ZpqrtBnk
by
1y ago
In a Twitter exchange with my friend James, we recently wondered how to properly document methods that return named value tuples. Why would we have to deal with methods returning value tuples? Well, consider this classic method: public bool TryGetValue(TKey key, out TValue value) { ... } Enters async. Ideally, we want: public async ValueTask<bool> TryGetValue(TKey key, out TValue value) { ... } But... async does support out parameters. And thus, the method logically becomes: public async ValueTask<(bool, TValue)> TryGetValue(TKey key) { ... } Which leads us to the original qu ..read more
Visit website
What Becomes Of Models Builder
ZpqrtBnk
by
1y ago
Models Builder is an Umbraco extension that generates C# strongly-typed class models for Umbraco content item. It allows developers to write @Model.Title in views instead of the more verbose @Model.Value<string>("title"). Models can be enriched and tweaked to greatly simplify the developement of sites. It was originally created in 2013 by me, Stephan, and distributed as an independent NuGet package named "Zbu.ModelsBuilder". Then, around 2016, it was considered sufficiently important to be bundled with the Umbraco CMS official distribution. On that occasion, it was renamed "Umbraco.Model ..read more
Visit website
Three Fives Kit PCB Edition
ZpqrtBnk
by
1y ago
Some time ago I built a Three Fives Kit from Evil Mad Scientist, and a quick circuit which blinked one LED with a real NE555 timer, and one with the kit. This has been sitting on some shelve in my office ever since, but I have always wondered whether I could clean things up a little... maybe building a PCB for the circuit. So, I asked on Twitter what people would use to design PCBs, and the always helpful and super-friendly maker Matt Brailsford from CircuitBeard suggested I tried KiCad. Downloading and installing KiCab is relatively easy, but then I quickly hit a steep learning curve. I star ..read more
Visit website

Follow ZpqrtBnk on FeedSpot

Continue with Google
Continue with Apple
OR