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.

Where Next?

Popular in Questions Top

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
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Tee
can someone please explain to me how Enum.reduce works with maps
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
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
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
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
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
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New

We're in Beta

About us Mission Statement