Async Does Not Imply Concurrent

I wish authors who write articles about C# async / await programming techniques would emphasize that two concepts they frequently discuss are actually separate features that provide separate benefits. Perhaps I’ve overlooked an explanation of the orthogonality of async and concurrent in the restaurant or cooking breakfast analogies. (Update 2020 Jul 30: The cooking breakfast article has been updated and draws a clearer distinction between async work and parallel / concurrent work). Nonetheless, it will benefit readers of this blog to disentangle the concepts here. It’s easy for novice programmers to write incorrect code and believe they’re getting performance benefits […]

The Best Domain-Specific Language for Manipulating Data is SQL

Motivation I’m not a fan of Microsoft’s Language Integrated Query (LINQ). But ranting about a language feature is an ineffective way to convince programmers of the merits of other techniques. So decided to construct a detailed example that illustrates how LINQ solves a certain problem, contrast it with a different technique, then highlight the deficiencies of LINQ and extol the virtues of my preferred technique. I happily set about creating a relational database and C# object model, then hit an impasse. When the time came to determine how to write LINQ code that maps the relational data into the C# […]

AES, A Stronger Cipher Than XOR

The Problem In a previous post, Encrypting and Decrypting Text, I discussed how the shared key derived from a Diffie-Hellman Key Exchange can be used with a simple cipher (XOR) to encrypt and decrypt text. I wrote a demonstration program that sends encrypted messages between a client and server, with the server knowing how to respond to funny lines from the classic comedy, Airplane! I concluded with a mysterious statement, “There’s a weakness in our simple XOR cipher that’s exposed by sending a message not recognized as a line from Airplane!” Let’s pick up there by sending a simple phrase […]

Encrypting and Decrypting Text

In a previous post, The Math That Enables Asymmetric Key Cryptography, I discussed how your web browser and a web server can establish an encrypted communication channel without requiring you and the web administrator to meet beforehand to exchange secret keys. I explained how your web browser and a web server exchange public keys, then perform math operations on their private keys and the exchanged public keys to derive the same shared key. And I emphasized the security of this technique (Diffie-Hellman Key Exchange) is guaranteed by the computational difficulty of determining the shared key from the partial information transmitted […]

Iterating over a Generic Dictionary

It can be tedious to iterate over a generic Dictionary in C#, especially if the Dictionary contains complex types. The values you’re interested in are properties of the iteration variable. I never know what to name the iteration variable (here I name it “pair”), which is an indicator this code is clumsy. Make it easier on yourself by using C#’s Tuple Deconstruction language feature. First, write an extension method for the generic KeyValuePair class. Or, instead of writing the extension method, you can add a reference to my ErikTheCoder.ServiceContract package and add a using ErikTheCoder.ServiceContract; statement. Then rewrite your foreach […]