Ever wondered why parametric tests in xUnit are called “theories”? And why tests are “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:
You need to setup Virtual Cam in OBS Studio.
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:
Playing Hansel and Gretel is just the excuse to happily slip into
yet another rabbit hole.
Let’s go!
Bookmarks are like Registers, with a few special traits:
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.
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?
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:
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
--first-parent
Or: how I learnt to stop resetting the DB after each integration test.
TL;DR
Just use unique identifiers and avoid absolute asserts
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:
Indeed, objects should be manipulated solely in terms of their interface, not in terms of their concrete types.
internal
, which is good for encapsulationDeriving 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).
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.
So, by using lambdas in the Fluent Builders our tests started containing expressions such as:
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.
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:
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.