Feed fabulous-adventures-in-coding Fabulous adventures in coding

Favorite IconFabulous adventures in coding

Link https://ericlippert.com/
Feed http://ericlippert.com/feed
Updated 2024-03-28 12:46
Porting old posts, part 2
I’m continuing my efforts to port over and update my old blog content. The previous episode is here. We’re still in the first few weeks of me blogging; I was pumping out articles at a rate I now consider to … Continue reading →
Fixing Random, part 21
Last time in this series I proposed a stripped-down DSL for probabilistic workflows. Today, let’s see how we could “lower” it to ordinary C# 7 code. I’ll assume of course that we have all of the types and extension methods that … Continue reading →
Porting old posts, part 1
Thanks again to the good people at Microsoft who have kept my old blog alive for now; my plan is to port the articles from the old site over, and then they will redirect from the old URLs to the … Continue reading →
Fixing Random, part 20
Without further ado, here’s my proposed stripped-down C# that could be a DSL for probabilistic workflows; as we’ll see, it is quite similar to both enumerator blocks from C# 2 and async/await from C# 5. (Code for this episode can … Continue reading →
Fixing Random, part 19
I’ve got no code for you this time; instead here are some musings about language design informed by our discussion so far. One of the most important questions to ask when designing a language feature is: what should the balance … Continue reading →
Fixing Random, part 18
Before that silly diversion I mentioned that we will be needing the empty distribution; today, we’ll implement it. It’s quite straightforward, as you’d expect. [Code for this episode is here.] public sealed class Empty<T> : IDiscreteDistribution<T> { public static readonly Empty<T> Distribution = new Empty<T>(); private Empty() { } public T Sample() => throw new Exception(“Cannot sample from empty distribution”); public IEnumerable<T> Support() => … Continue reading →
Fixing Random, bonus episode 1
I just thought of a really cute application of the stochastic workflow technology we’ve been working on; most of the series has already been written but it fits in here, so I’m going to insert this extra bonus episode. We’ll … Continue reading →
Fixing Random, part 17
Before we get going on today’s episode of FAIC, you might want to refresh your memory of what an additive monad is; I wrote an episode of my monad series on this subject. Briefly, an additive monad is a monad … Continue reading →
Fixing Random, part 16
[Code is here.] This series is getting quite long and we’re not done yet! This would be a good time to quickly review where we’re at: We’re representing a particular discrete probability distribution P(A) over a small number of members … Continue reading →
Fixing Random, part 15
[Code is here.] Last time on FAIC we made a correct, efficient implementation of SelectMany to bind a likelihood function and projection onto a prior, and gave a simple example. I deliberately chose “weird” numbers for all the weights; let’s … Continue reading →
So long, MSDN blog
UPDATE 3: Rock stars Scott Hanselman and Dan Fernandez and their colleagues have gotten my MSDN blog back up, and will also restore the late cbrumme’s blog as well. Thank you both, and everyone else at what I can only assume … Continue reading →
Fixing Random, part 14
[Code is here.] Last time on FAIC we achieved two major results in our effort to build better probability tools. First, we demonstrated that the SelectMany implementation which applies a likelihood function to a prior probability is the bind operation … Continue reading →
Fixing Random, part 13
[Code is here.] Last time on FAIC we discovered the interesting fact that conditional probabilities can be represented as likelihood functions, and that applying a conditional probability to a prior probability looks suspiciously like SelectMany, which is usually the bind … Continue reading →
Fixing Random, part 12
[Code is here.] Last time on FAIC we implemented an efficient “conditioned” probability using the Where operator on distributions; that is, we have some “underlying” distribution, and we ask the question “if a particular condition has to be met, what … Continue reading →
Fixing Random, part 11
[Code is here.] Last time on FAIC we drew a line in the sand and required that the predicates and projections used by Where and Select on discrete distributions be “pure” functions: they must complete normally, produce no side effects, … Continue reading →
Fixing Random, part 10
[Code is here.] We’re going to spend the next while in this series on expressing probabilities that have some sort of extra condition associated with them. We’ll start with a simple example: I want to roll a fair six-sided die, but … Continue reading →
Fixing Random, part 9
[Code is here.] Last time on FAIC I sketched out the “alias method”, which enables us to implement sampling from a weighted discrete distribution in constant time. The implementation is slightly tricky, but we’ll go through it carefully. The idea … Continue reading →
Fixing Random, part 8
[Code is here.] Last time on FAIC we sketched out an O(log n) algorithm for sampling from a weighted distribution of integers by implementing a discrete variation on the “inverse transform” method where the “inverse” step involves a binary search. … Continue reading →
Fixing Random, part 7
[Code is here.] A few episodes back I made a version of the Bernoulli distribution that took integer “odds”. That is, the distribution randomly produces either zero or one, and we can say “produce on average 23 zeros for every … Continue reading →
Fixing Random, part 6
[Code is here.] Last time on FAIC I showed how we could implement more of the standard, straightforward probability distributions, like the Bernoulli distribution; the episode before I showed the standard discrete uniform distribution, also known as “roll an n-sided … Continue reading →
Fixing Random, part 5
[Code is here.] Last time on FAIC I implemented our first discrete distribution, the “choose an integer between min and max” distribution. I thought I might knock out a couple more of the easy discrete distributions. The easiest discrete distribution … Continue reading →
Exhausting vs exhaustive
We briefly interrupt my ongoing exploration of stochastic programming to point you at a new blog about pragmatic programming language design. My friend and erstwhile Roslyn colleague Anthony is once more living in Chicago and has just started blogging anew, … Continue reading →
Fixing Random, part 4
[Code is here.] Last time on FAIC I showed how we could use a simple interface to cleanly implement concepts like “normal distribution” or “standard uniform distribution” in a natural style using fluent programming. For the next many episodes we’ll … Continue reading →
Fixing Random, part 3
[Code is here.] Last time on FAIC I described a first attempt of how I’d like to fix System.Random: Make every method static and threadsafe Draw a clear distinction between crypto-strength and pseudo-random methods There were lots of good comments … Continue reading →
Fixing Random, part 2
[Code is here.] Last time on FAIC I complained bitterly about the shortcomings of System.Random. In this episode, I’ll take a stab at the sort of thing I’d like to see in a redesigned random library. This is the “fix … Continue reading →
Fixing Random, part 1
[Code is here.] How to say this delicately? I really, really dislike System.Random. Like, with a passion. It is so… awful. The C# design team tries hard to make the language a “pit of success”, where the natural way to … Continue reading →
An interesting list structure, part 3
This is the story of how I was no-hired by Microsoft; surprisingly, it is germane to our discussion of unusual list structures. I was a Waterloo co-op intern three times at Microsoft, each time working for the Visual Basic team; … Continue reading →
An interesting list structure, part 2
Last time on FAIC I gave a standard implementation of a persistent immutable linked list, with cheap — O(1) — Push, Pop, Peek and IsEmpty operations, and expensive — O(n) — Append and Concatenate operations. In this episode we’re going … Continue reading →
An interesting list structure, part 1
As long-time readers of my blog know, I’m a big fan of functional persistent immutable list data structures. I recently learned about a somewhat bizarre but very practical implementation of such lists, and naturally I wanted to implement it myself … Continue reading →
Indexer error cases
Pop quiz: Consider these little methods. (They could be static, inline, whatever, that doesn’t matter.) int[] A1() { Console.WriteLine(“A”); return new int[10]; } int[] A2() { Console.WriteLine(“A”); return null; } int B1() { Console.WriteLine(“B”); return 1; } int B2() { Console.WriteLine(“B”); return 11; } int C() { Console.WriteLine(“C”); … Continue reading →
Dual numbers, part 4
Last time on FAIC I gave a hand-wavy intuitive explanation for why it is that lifting a function on doubles to duals gives us “automatic differentiation” on that function — provided of course that the original function is well-behaved to … Continue reading →
Dual numbers, part 3
Last time on FAIC we discovered that when you “lift” a polynomial on doubles to a polynomial on duals and then evaluate it with x+1ε, the “real” part of the returned dual exactly corresponds to the original polynomial at x; … Continue reading →
Dual numbers, part 2
Last time on FAIC I introduced a fun variation on complex numbers called “dual numbers” consisting of a value “plus a tiny bit” notated as ε, where the really tiny part has the interesting property that ε2 is zero. Well, … Continue reading →
Dual numbers, part 1
I’ve recently been looking into a fascinating corner of mathematics that at first glance appears a little bit silly, but actually has far-reaching applications, from physics to numerical methods to machine learning. I thought I’d share what I’ve learned over … Continue reading →
Accessibility of nested classes
Happy New Year all and welcome to another year of having fabulous adventures in coding. I thought I’d start this year off by answering a question I get quite frequently: I have a public outer class with a public nested … Continue reading →
Removing a recursion in Python, part 2
Good day all, before we get into the continuation of the previous episode, a few bookkeeping notes. First, congratulations to the Python core developers on successfully choosing a new governance model. People who follow Python know that the Benevolent Dictator … Continue reading →
Removing a recursion in Python, part 1
For the last two decades or so I’ve admired the simplicity and power of the Python language without ever actually doing any work in it or learning about the details. I’ve been taking a closer look lately and having a … Continue reading →
Adventures in podcasting
Many thanks to Phil Burgess, who invited me to be this week’s guest on his podcast, IT Career Energizer. I enjoyed our conversation, and I’m looking forward to listening to past episodes. Check it out on the link above, or … Continue reading →
A dynamic definite assignment puzzle, part 2
Sorry for that unexpected interlude into customer service horrors; thanks for your patience and let’s get right back to coding horrors! So as not to bury the lede: the C# compiler is correct to flag the program from the last … Continue reading →
Not so fabulous adventures in banking
I’ve banked with First Tech Credit Union since 1994, when they were the only bank that would give a non-resident Microsoft intern like me an account. I had nothing but good service from them for many years, but in the … Continue reading →
A dynamic definite assignment puzzle
I’ve often noted that “dynamic” in C# is just “object” with a funny hat on, but there are some subtleties to that. Here’s a little puzzle; see if you can figure it out. I’ll post the answer next time. Suppose … Continue reading →
Anti-unification, part 6
Last time I gave a simple C# implementation of the first-order anti-unification algorithm. This is an interesting algorithm, but it’s maybe not so clear why anti-unification is useful at all. It’s pretty clear why unification is interesting: we have equations … Continue reading →
Anti-unification, part 5
Last time we wrote all the boring boilerplate code for substitutions and trees. Now let’s implement the algorithm. As I noted a couple of episodes back, we can reduce the algorithm to repeated application of two rules that mutate three … Continue reading →
Anti-unification, part 4
All right, let’s implement this thing. We’ll start with a few caveats: In the previous post I worked an example on function calls; in this code, we’ll do the algorithm on syntax trees. Hopefully it is obvious that they’re equivalent. … Continue reading →
Anti-unification, part 3
Last time we described the classic first-order anti-unification algorithm, and reduced it from three rules to only two. Let’s work an example, the same example that we gave a while back. s is cons(cons(1, 2), cons(cons(1, 2), nil)) t is … Continue reading →
Anti-unification, part 2
Last time on FAIC we learned what the first-order anti-unification problem is: given two expressions, s and t, either in the form of operators, or method calls, or syntax trees, doesn’t matter, find the most specific generalizing expression g, and … Continue reading →
Anti-unification, part 1
Last time on FAIC we noted that there was a simple, recursive, linear-time first-order unification algorithm. We didn’t give the algorithm, but hopefully you see how it would go. The point is, we start with two expressions that contain some … Continue reading →
Unification, part 2
Last time on FAIC I defined unification as a fancy word for taking a system of statements that contain placeholder variables and finding values for those variables which make the statements all true. We’ve seen that we can do that … Continue reading →
Unification, part 1
My long and not-yet-finished series where I did a line-by-line exegesis of the seminal paper on ML type inference ended with a discussion of the type unification algorithm. In reading back over that episode I realize to my horror that … Continue reading →
That was a long break
Well that was a much longer break than I intended! In fact I did not intend any break at all. As I’m sure you’ve deduced, I batched up a whole long series of blog articles when things were relatively calm, … Continue reading →
123456