crispinb

crispinb

How do you approach exploratory programming in Elixir?

The background to this is that I’ve (a) recently been doing some Clojure and am slightly addicted to the REPL-connected editor, and (b) I’m a total Elixir beginner (1 week in), so all my coding is at this stage “exploratory” (playing with examples from what I’m reading, trying out Kernel functions, etc).

Here’s what I’ve come up with so far:

  • iex: fine for one-liners, but a bit clumsy for anything more, and I’d much rather use an editor (and preferably the same editor I would use for real code)
  • iex -S mix, then calling on functions in files, reloading after edits: better, but still more friction than I’d like
  • via unit tests, writing small tests for the exploratory code & running mix test. A variation here is to use fswatch to run tests on every file save, but I haven’t got this working yet.
  • again via unit tests, but triggering tests from the editor (in my case using GitHub - adamzapasnik/vscode-elixir-test-explorer: VSCode Elixir test explorer).

The final one above seems the most fluent approach so far, definitely workable, though ideally I’d like not to have to write tests for this kind of very transient exploratory code.

Any other ideas? I realise I’m not going to get a lisp-style repl experience (which is fine - Elixir has its own virtues), but something in that direction would be nice. A non-clojure example I quite like is Quokka for javascript/typescript.

Most Liked

Marcus

Marcus

Maybe you will find exsync and mix-test.watch useful.

mindok

mindok

If I was starting out and wanting to play around with code, LiveBook (https://livebook.dev/) would probably be my #1 choice now. Instant feedback, nice formatting etc.

hauleth

hauleth

Well, you can start the “REPL-like” server that will receive the code, and then will use Code.eval_string/3 to execute whatever you throw at it. It will provide similar experience to the SLIME.

About unit testing, what I am using is entr. So you need to list all files in your project (I am using rg -l -telixir '', but you can use git ls-files instead) and then make it to output name of the changed file entr echo /_ that will pass the changed files to mix test --listen-on-stdin --stale. So whole CLI will look like:

rg -l -telixir '' | entr echo /_ | mix test --listen-on-stdin --stale

Now it will changed tests on each save.

crispinb

crispinb

Agreed, it’s terrific. Not exactly the same as using your own REPL-linked editor (different keybindings etc), but with lots of other great possibilities.

crispinb

crispinb

I do know about r/1 now but the question was a while back and I have no idea whether I did or not back then (or whether that was what I meant by ‘reload’). So thanks from my erstwhile self!

Ironically (or sadly from this perspective) I’m doing more with Rust right now than Elixir, so I’m even further distant from REPLy goodness.

Where Next?

Popular in Questions Top

LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement