Tag: <span>C#</span>

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…

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.

This entry is part 7 of 11 in the series Mazes For Programmers

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…

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.