Elixir Metaprogramming : the basics

Elixir has a very small core language. Most of what is thought of as the syntax is actually written using macros.

Elixir makes it ridiculously easy to get at the Abstract Syntax Tree (AST) of the code that you are using.

How to get the AST of some code:

iex(1)> quote do: 1 + 1
{:+, [context: Elixir, import: Kernel], [1, 1]}

New Machine Setup

I have recently moved jobs. This comes with the inevitable machine setup issue.

This is a list of things that I have been installing on my machine so that I won’t have to build myself another list:

  • Chrome
  • homebrew
  • neo4j
  • java8
  • elixir
  • exercism
  • vscode
    • Enable autosave (on the file menu)
    • GitLens
    • IntelliJ IDEA Keybindings
    • JS Refactor
  • Gradle
  • git ssh setup

After every mac os upgrade:

xcode-select –install

Development Practices That I Want To Use In Future Roles

I have just left one company for a new role. These are a few notes that I would like to bring forward to future companies:

  • Empower the devs add cloud resources within a limit say $100 per month without having to ask. The meetings to request this will cost more than the benefits. Dev teams will spend less time waiting.
  • Have a bell that can be used to trigger team timeouts. Hold the discussions as soon as they are needed. Decisions should be made by the team. Go one better than us and actually write up the decision including why’s and assumptions.
  • When adding a new piece of technology always consider how to replace it. Cloud services do stop with anything between 1 and 6 months notice.
  • Actively monitor the cloud infrastructure bills, both current and projected. Warn the team daily if a threshold is breached.
  • Never let the build stay broken. You can only ignore tests for a fixed period of days. This is only to be used for infrastructure failures.
  • Deploy frequently. Weekly at a minimum. Code not deployed will rot. Use feature switches if possible (but ruthlessly remove them after a feature is live). This does allow deploy from master.

Script to help review Exercism.io Elixir


@rem fix a.test.exs
@rem removes the pending tag from the test and adds _2 to filename
@echo %1 | sed -e "s/.exs/_2.exs/" > temp.txt
@set /p Filename=<temp.txt
@cat %1 | grep -v "@tag :pending" > %Filename%
@rm temp.txt
elixir %Filename%

view raw

fix_test.bat

hosted with ❤ by GitHub

Or on a mac/linux

grep -v @tag *_test.exs > test.exs && elixir test.exs

Contentful to Neo4j in Elixir

I just finished an initial port of my neo4j to contentful library from Node to Elixir.

https://github.com/chriseyre2000/contentful_to_neo4j_ex

This is the same utility but in a very different language. It’s not quite as polished as the Node version (but won’t take long to catch up).

Issues that I have had during the port:

  • My machine had a very old erlang implementation (I had installed this when reading the Erlang chapter of 7 languages in 7 weeks – over 7 years ago) which broke HTTPoison, a fairly common HTTP library. The errors pointed to HTTPoison not working on a windows machine (which I have found to not be true).
  • The Contentful Elixir bindings are not very advanced. They don’t return the total number of items that you are paging through. It was not difficult to use the api directly.
  • There are lots of Elixir bindings for Neo4j. Very few of them are clearly documented for writing to Neo4j. Eventually I landed on bolt_sips. Bolt is too primitive, neo4j_sips uses a very old version of HTTPoison.

The Elixir error messages are incredibly clear.

Credo is great for ensuring best practices are applied.

Functional programming allows you to test real code without mocks or spend time fighting promises.

iex is a great REPL environment. You can recompile a module and carry on without restarting everything.

The code is self documenting. This is the top level method:

read_all_assets()
|> read_all_entries
|> process_contentful
|> write_to_neo4j
VSCode is a great editor for elixir. It’s great from the command line
code .
The above will open vscode on the project in the current directory.