Let’s develop squint a little package for controlling the font height, so you won’t need to squint your eyes when you are on smaller screens.
It will look like this:

It will give us the chance to touch on:

  • Face attributes.
  • Asking the user to choose interactively from a list of options.
  • The powerful consult--read.
  • Lisp’s Dynamic and Lexical Binding.
  • Few other little topics here and there.

Ever wondered why parametric tests in xUnit are called “theories”? And why are tests called “facts” instead of, well, just “tests”?

Investigating on this topic helped me realize that I have always used xUnit theories incorrectly. And that xUnit loves the idea of Property-Based Testing.

Distilling the State Monad from the very ground up. In F#, no prior knowledge needed.

I’ve always had trouble remembering the subtle differences between FoldLeft and FoldRight, and have constantly found myself consulting Hoogle over and over.
Overtime, I collected some mnemonics to help my gold fish memory.
I hope they can help you too.

We all know how to use git commit --amend to fix up the very last commit.
How beautiful would it be to have a command like:

git commit --amend=3

to extend this power to fix up the 3rd to last — or any other past — commit?

Enter git fixup.

So you want to code in F# with Emacs?
I can relate, I also love both. Oh dear, if I love them!

So, presto! Let’s make Emacs your next F# IDE!

You want both:

  • to stream your cam during a video call
  • and to record the original cam output to a file.

You need to setup Virtual Cam in OBS Studio.

  • OBS Studio will record the original cam video.
  • It will forward the stream to a virtual device.
  • Jitsi will stream the virtual device video.

Playing Hansel and Gretel

In our exploration of the ways to navigate back to previous buffer positions, Registers can be seen as mark ring items with an assigned name, so that they can be conveniently accessed by that name in an arbitrary order.
But in fact they are much, much more:

  • They can be persisted so they survive reboots.
  • They can resurrect killed buffers.
  • Other than buffer positions, they can contain snippets of text, keyboard macros, windows layouts and even custom values.

Playing Hansel and Gretel is just the excuse to happily slip into yet another rabbit hole.
Let’s go!

Playing Hansel and Gretel

Bookmarks are like Registers, with a few special traits:

  • They are long-lived (they survive reboots).
  • They can re-open closed buffers.
  • They have arbitrarily long names.
  • They are context aware.

Consider them as specialized, super convenient Registers.

A cool trick not everybody knows with Visual Studio and JetBrains’ IDEs is that it is possible to navigate back to previous positions with Ctrl -.

A similar trick also works with Bash:

cd -

and with Git:

git checkout -

Neat, right?
Of course, there are way more powerful tools built around this idea (such as z, autojump and zoxide). And — did you doubt? — similar powerful features are in Emacs too. Let’s explore them.

Playing Hansel and Gretel

Rings — fixed sized variables acting as circular buffers — are a beautiful idea: one day I will eventually write something about how undoing changes is handled in Emacs with the undo-ring. I find outrageous that other editors have not followed the same idea.

In the previous installment we learnt how to surround a region with hard-coded <<< and >>>. Let’s learn now how to interactively ask arguments to the user and to go beyond hard-coded delimiters.

Or: booleans can be very ambiguous without context, as in:

A Prolog programmer is delivering a baby.

The mother asks, “Is it a boy or a girl?”

and the Prolog programmer says: “Yes”.

I refuse to see the tension between theory and practice.
I love the sentence:

In theory there is no difference between theory and practice.
In practice there is.

It is very, very funny, I love to cite it when I can. But I cannot help but think it is false — I will write about this, some time.

Let’s talk about mathematical notions. I hear way too many times

Yes, hey are universal and profound. But practically useless.

I hate this.

With this post I challenge myself to debunk this notion. I chose a very abstract notion — the concept of cardinality of types — and challanged myself to find pragmatic uses of it in the everyday programmer’s life.

Can there be a more useless and theoretical notion that cardinality?

  1. Select a region.
  2. Let Emacs surround it with custom delimiters.
  3. Profit.
  • When a file of type Y is opened, Emacs sets a specific major mode.
  • Each major mode is equipped with a hook, a variable holding a list of functions.
  • After that major mode is activated, all the functions in its hook are run.
  • If you add a function to the mode’s hook it will be run for that kind of file.
  • You can use `add-hook` for that.

Therefore, just use:

(add-hook '<major-mode>-hook #'<function-you-wish-to-trigger>)

For example, to have line numbers in your Python files, use:

(add-hook 'python-mode-hook #'display-line-numbers-mode)

Virtually all the tutorials on Monads introduce them only after a lengthy discussion about Functors, and often resorting to intrepid and debatable metaphors.
I dare to take a different path and to go straight to the point, following what Mike Vanier did in his seminal 8-post series Yet Another Monad Tutorial.

I challenged myself to write a post that:

  • prioritizes code over storytelling
  • uses no metaphors (no boxes, no burritos)
  • does not require Category Theory
  • jumps past the discussion why Functional Programming is valuable
  • does not follow the classical Functors -> Monads narrative
  • is tailored for C# developers and digestible by Java ones

This is an appendix of You probably don’t need MediatR: it offers practical guidance to implement the MediatR’s functionalities using a plain object-oriented approach.

It goes through all the examples in the MediatR readme file and all the snippets in the ‘samples’ project: for each of them, it provides an implementation based on OOP standard patterns, together with some design considerations.

It’s no secret that getting started with Property-Based Testing (PBT) is hard. This series of articles does not have the presumption of changing this fact. It is merely the outcome of the observations and thoughts I have gathered during my personal journey.
By no means is this a comprehensive manual. Consider it as a friendly introduction to help dispel the fear.

I will rely on C# examples with FsCheck, although my heart is with Hedgehog.
All the code samples are on GitHub.

Note: do you prefer to start directly with a practical example? Go straight with the 4th installment.

Did you know Bash has got macros, a multi-clipboard, an undo feature, and a word completion based on history?

If you prefer watching videos to reading posts, you can check it out here.

TL;DR

  • Even without squashing, Pull Requests already include a squashed commit
  • You can get an on-the-fly squashed view of history using --first-parent
  • Squashing would not save space
  • Squashing makes git bisect less effective
  • Once squashed, details are lost forever
  • Joining is easier than separating
  • Squashing may promote sloppy habits
  • Don’t squash, rebase

Or: how I learnt to stop resetting the DB after each integration test.

TL;DR

  • Cleaning database tables after each integration test is not stictly needed
  • It’s often not even desirable
  • Tests can be easily made independent from the initial DB state and from each other
  • Just use unique identifiers and avoid absolute asserts

  • Tests designed like this can be run in parallel
  • They run faster
  • And they are more resilient and realistic

A tattoo with the Y Combinator

What the heck is that? That’s the Y Combinator!
Uh? A higher-order function with which anonymous lambdas can be made recursive.
Sounds useful, I guess? No, it’s not. It’s a purely intellectual challenge.
Any practical application for my C# developer daily life? Not at all.
So, what’s the point? Why? Because it’s fun.

Variables are just syntactic sugar for lambda expressions: they are not stricly necessary and ideally C# could happily live without them. Even the reseved word var could be eliminated.

In this post we will use ReSharper for refactoring variables away, transforming them to anonymous lambda expressions.

That’s a trick that will come in handy for deriving the Y Combinator.

git stash is very convenient to quickly switch to another branch without loosing your changes.
What if you wish to browse both your changes and another branch?
worktree lets you checkout more than one branch at a same time.

Could you explain the following?

[Test]
public void puzzling_test()
{
    IEnumerable<string> strings = SomeStrings;
    Assert.AreEqual(new[] { "Foo", "Bar", "Baz" }, strings.ToArray());

    var test1 = strings.Select(s => new string(s.ToCharArray()));
    Assert.AreEqual(new[] { "Foo", "Bar", "Baz" }, test1.ToArray());

    var test2 = strings.Select(s => "" + new string(s.ToCharArray()));
    Assert.AreEqual(new[] { "Foo", "Bar", }, test2.ToArray());
    // Hey, what happened to Baz??

    try
    { 
        var test3 = strings.Select(s => new string(s.ToCharArray()) + "");
        Assert.Null(test3.ToArray());
    }
    catch (PlatformNotSupportedException)
    {
        Assert.Pass();
    }
            
    var test4 = strings.Select(s => new string(s.ToCharArray()) + "");
    Assert.AreEqual(new[]
    {
        "Argument Foo of type System.String is not assignable to parameter type int32",
        "Argument Bar of type System.String is not assignable to parameter type int32",
        "Constructor 'Baz' has 0 parameter(s) but is invoked with 0 argument(s)"
    }, test4.ToArray());
}

MediatR is a very popular library used to reduce dependencies between objects. It advocates an architecture based on very valuable design principles:

  • not allowing direct communication beetween objects, it promotes loose coupling
  • it leads toward a Message-Oriented Architecture
  • it supports an asynchronous in-process messaging
  • it promotes reuse object
  • A C# classe can implement an interface either implicitly or explicitly
  • Implement explicitly wherever possible: it is a good practice
  • In fact, there are rare cases for Implicit Implementation.
  • Indeed, objects should be manipulated solely in terms of their interface, not in terms of their concrete types.

  • With Explicit Implementation methods can be internal, which is good for encapsulation
  • Explicit Implementation is a design best practice, as it promotes Loose Coupling and enforces the Dependency Inversion Principle.
  • It gets rid of Ghost Public Methods, promoting maintenaibility

Deriving the Y-Combinator from a recursive implementation of factorial

The following code is just legit:

class Foo
{
    private string _privateField;
    
    void DoSomething(Foo anotherInstance)
    {
        anotherInstance._privateField = "doh!";
    }
}

This post describes a possible approach for registering components with circular dependencies (e.g. Foo needs Bar, and Bar needs Foo) with Autofac, with both components taking their dependencies through their constructor (the so called Constructor/Constructor Dependencies).

TL;DR

Use an Implicit Relationship Type and inject Lazy<Foo> instead of Foo.

git cherry-picks seems to be detaching a commit from its parent and to be attaching it to a new parent. But this is just an illusion: as a matter of fact, cherry-pick moves patches, not commits. That’s why cherry-picking a commit you can have conflicts.

Actually, it’s simpler that it seems. Bear with me.

Some tools and Git hosting services promote the addition of pre-baked .gitignore files to repositories at their creation.
GitHub, for example, offers the option to add long, 300+ lines, pre-compiled .gitignore files with a single click.

While initializing a repository with a README and a License is a very good idea, using pre-baked .gitignore files isn’t. It violates YAGNI and it may cause puzzling situations.

A better alternative is a global .gitignore file.

Setup a one-node, private Ethereum network in a Docker container.

So, by using lambdas in the Fluent Builders our tests started containing expressions such as:

    var order = new OrderBuilder()
        .WithNumber(10)
        .WithDate(new DateTime(2018, 12, 24))
        .HavingArticle(a => a
            .WithPrice(32.50m)
            .WithCategory("books"))
        .HavingCustomer(c => c
            .WithName("Amelia"))
        .Build();

We found that this improved the readibility of tests, making them a bit more intelligible by non-technical people.

While the goal was not to implement BDD tests – which are more conveniently written with specialized libraries – we felt that the tests could benefit from having an even more fluent syntax, possibly using language closer to domain than to the technical implementation.

    var order = AnEmptyOrder()
        .WithNumber(10)
        .CreatedOn(new DateTime(2018, 12, 24))
        .ByACustomer(c => c
            .Named("Amelia")
            .Aged(42))
        .ContainingAnArticle(a => a
            .WithPrice(32.50m)
            .InCategory("books"))
        .Build();

We show how we designed our C#, domain-focused, fluent builders that support nested entities by using lambdas.

SICP doesn’t cease to amaze me. Here’s a challenge for you to solve, which I found in the chapter Building Abstractions with Data. I will provide a solution in C#.

The quiz is:

Would you be able to implement a 2-tuple (a pair) of integers, only leveraging functions and lambdas, without using neither variables nor class fields?

While reading Structure and Interpretation of Computer Programs, I got hit by this sentence (p. 65):

“A let expression is simply syntatic sugar for the underlying lambda expression”

It claims that variables definition is not a necessary language feature, and that it has been introduced only as a convenient alternative to lambda expressions.

WAT? Seriously?

While reading Structure and Interpretation of Computer Programs, I got hit by this sentence (p. 65):

“A let expression is simply syntatic sugar for the underlying lambda expression”

It claims that variables definition is not a necessary language feature, and that it has been introduced only as a convenient alternative to lambda expressions.

WAT? Seriously?

You might have noticed that after a fresh MiniShift installation the admin user cannot see system projects openshift, openshift-infra, kube-public, kube-system and default, so, trying to switch to one of them results in an error:

$ oc login -u admin -p admin
$ oc project openshift
error: You are not a member of project "openshift".
You have one project on this server: My Project (myproject)
To see projects on another server, pass '--server=<server>'.
If you are learning to touch type, use this cheat sheet. Print it, and forget the keyboard.

Registering components in Autofac is straightforward, as long as no primitive dependencies (such as connection strings, URLs and configuration parameters in general) are involved.
This post describes the strategy for dealing with primitive dependencies.