I’ve been trying to write functional code for some time now, and still have the feeling that I’m not doing it correctly, especially when seemingly simple things don’t work. Having bumped into one specific issue over and over again, I decided to try and sort it out once and for all. Imagine a stupidly simple API endpoint that take a float, and returns the square root doubled. I have helper functions as follows… My API endpoint returns a string of the form “Result: 23.3” if successful, or an error if not. I wire these together as follows… This works as expected. Obviously, my real code would have more from clauses than this, but I’m trying to keep this simple. Now, suppose (which is more realistic) the helper functions were async, then I would need to modify my endpoint to look like this… Again, all works. However, now in the case…
Tag: <span>C#</span>
My attempt to write some C# that would differentiate mathematical expressions, following some Lisp code I saw in a book
My C# solution to LeetCode problem 222, counting islands. A first (slightly incorrect) attempt in a procedural manner, followed by a Linq solution that worked
Quick post on how to convert from an integer to its equivalent hex value and back again in C#. Written as a reminder for myself, as I forget every time!
The “with” keyword is a crucial part of a functional programmer’s toolbox, but is sadly lacking in C#. In this blog post, I document the development of a template that will automatically generate a With() method for C# classes.
How to generate classes to represent discriminated unions in C#
As mentioned in the previous post in this series, I decided not to convert his Ruby code into C#, but rather to read his description of the algorithm, then try and write my own code. This way I am forced to understand the algorithm, which is far more productive than simply copying out someone else’s code without really knowing what it does. I had actually seen his code for Aldous-Broder, so had a basic idea of how he went about it, but hadn’t looked at it very closely, so was mainly writing it myself. The end result was actually very similar to his. One thing I discovered when running it was that my mazes were anything other than non-biased. Pretty much every maze I generated had an empty corridor right across the top row, leading me to realise that I had done something wrong. Furthermore, every now and then, the…
Part 4 in my ongoing series of how I implemented the code from Mazes For Programmers by Jamis Buck in C#.
In this post, I explain how I implemented the first two maze-generation algorithms in C#, and show how parts of the code were improved by using Linq.
One of our main applications involves interacting with a third-party API. Whilst this is generally stable, we have had cases recently where it was throwing random exceptions. We could make the same request with the same parameters multiple times, and sometimes it would work, and sometimes it wouldn’t.
While we left the owners of the third-party API scratching their heads, we realised that the way we handled interaction with such APIs wasn’t robust enough. The first (and most obvious) improvement would simply be to try again.
As this is the sort of thing we’d want to do in a number of places, rather than repeat the same boilerplate code over and over again, we looked for a helper class.
We had a situation in which application users were not checking the customer list before adding new customers, which was resulting in multiple entries for the same customer. We wanted to make it so that when they tried to add a new customer, they would be shown a list of possible duplicates.
It turned out that finding duplicates wasn’t as easy as I thought. I ended up with a helper class that used Metaphones to find similar customers. This post describes the class, and shows how to use it.
Leave a Comment