Classic Elixir Bug

Data in Elixir is immutable. This can lead to some subtle bugs.

Here is the example Ecto.Multi sample

defmodule PasswordManager do
  alias Ecto.Multi

  def reset(account, params) do
    Multi.new()
    |> Multi.update(:account, Account.password_reset_changeset(account, params))
    |> Multi.insert(:log, Log.password_reset_changeset(account, params))
    |> Multi.delete_all(:sessions, Ecto.assoc(account, :sessions))
  end
end

This could be rewritten as

defmodule PasswordManager do
  alias Ecto.Multi

  def reset(account, params) do
    multi = Multi.new()
    multi = Multi.update(multi, :account, Account.password_reset_changeset(account, params))
    multi = Multi.insert(multi, :log, Log.password_reset_changeset(account, params))
    multi = Multi.delete_all(:sessions, Ecto.assoc(account, :sessions))
  end
end

Forget to capture the multi at any step and you will lose the specific change from the batch.

This is insidious when moving from the first to the second to add a calculated value or when the function you are adapting only uses one multi

Wheel of Time season 2

After watching season 1 of wheel of time I started reading the books. Currently I am on book 13 of 14. This article is trying to be spolier free.

The TV adaption was always going to differ from the books. We are not going to get 14 seasons with all of the characters

Season 1 did a good job of introducing the world, and managed to introduce some characters earlier than we would otherwise have met them.

Starting the characters off a little older than the books returns to the authors intent, before being asked by his publisher to make them younger.

Critical numbers have been reduced and there are 8 Forsaken and it only takes 8 to still someone – these required 13 in the books.

There is a slight flaw in timing in the new episodes. Perrin is with a group tracking Pendan Fain from the end of the previous season yet the group in the White Tower seem to have been there longer. This could just be a syncronisation issue with his letter being written and received some time later.

Several of the characters are in different places to the book. Rand and Matt need to be with Perrin. Matt could join the girls on their trip to the coast later on. Not sure how Rand will make the journey.

An interesting note on the opening catchup – all characters that were focussed on will be important later on.

Security > Usabilty

Recently there have been a number of changes to systems in the name of Security.

Security is a good thing, but so is being able to use a system.
A system is perfectly secure if no-one can use it. However it scores zero on the usability scales.

Consider a useful balance.

For example some systems insist on emailing a code to confirm logins. This can be useful.
The login link expires after a finite time, also a good idea.

When the link expires before the email is delivered or is invalidated when the next is requested will lead to loops where it is not possible to access a system.

Storybook is Amazing

I have recently added Storybook to one of the UIs that I am working on.

Storybook is an envitonment for providing a place to display UI components in a catalog. Typically this is used for development of a component library.

It is also useful slightly higher up the stack. Having entire forms or parts of forms testable in isolation is a big win. This allows you to show a form in all its possible states, even if some of them would require exotic conditions.

This can greatly free up development time while ensuring that the component can be refactored.

Having the components testable in isolation makes testing cross browser much easier. You can stand up Storybook locally without any backend services.

Given that I mostly work on an application with a React frontend with a GraphQL backend this reduces the effort on isolating changes to the frontend. So far I have not managed to use the fake GraphQL services, but by splitting the components into GraphQL layers and a pure function allows the pure function to be tested.

Magic The Gathering

I am just getting back into this game.
The last time I had played was 1997 so the modern game is very different.

The new restricted formats are an interesting twist.

Pauper – 60 or more cards, only if they have ever been common.

Commander – 1 Commander and 99 cards. No duplicated cards except for basic lands. There are a few exclusions.

The mana burn rule has been removed so you don’t need to have sinks for using up all of the spare mana you have floating around.

Mulligans help avoid the no land/all land hands.

The second step of the Mtg Online tutorial opponent could have been using my first Pauper deck, with Raging Goblins and Goblin Grenade!

I started to build my own commander decks from my collection. Only when checking the counts of the cards I found that the following two were banned:

  • Balance
  • Limited Resources

    I can see how devastating Limited Resources could be in multiplayer commander! Only having 10 lands across all of the players could mess up most decks.

Eyre’s First Law

If a utility is useful for testing it will eventually make its way into production.

I have seen this pattern many times.

You add a piece of code (possibly to help set up a test) that sets some state.
This then gets extracted from the test to a shared library.
It then gets added to the backoffice tool for development purposes.
This is then required for production.

Elixir Editor Fonts

The Fira font improves the Elixir Developer experience.

This is how to install it on a mac
`
brew cask install font-fira-code
brew install font-fira-code --cask

`For vscode in settings.json:
    "editor.fontFamily": "'Fira Code'",
    "editor.fontLigatures": true

This turns |> into an arrow. 

The Resignation That Wasn’t

Last Friday Boris Johnson announced that he was resigning with immediate effect and wrote a long resignation letter. The press have announced that he has resigned.

However there is as yet no date announced for the by election!

It appears that he has managed to announce a resignation without actually formally resigning as an MP.

The UK has a very odd system for MPs. The can’t technically resign. Insead they have to apply for one of the nominal positions that disqualify them from being an MP.

In this case it does not seem to have happened. This is also true for the other two that announced their resignations the same day.

Correction:

He did actually resign on Monday