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 · GitHub).

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.

Last Post!

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

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement