Work flow using mix/iex

[Duplicate of post to google group, before I realized that group was deprecated]
Presume I am creating a new application with these commands:

mix new my_app
cd my_app

I then use the editor of my choice to put some functions into lib/my_app.ex

If I want to test those functions in iex, am I best off doing this:

iex -S mix

or

cd lib
iex

If I do the former, then when I make changes to the source file, I have to do this in iex:

c("lib/my_app.ex")

whereas the second version needs only

c("my_app.ex")

Both of these seem to work equally well. Which is the correct or preferred way, if either? Or is there a “best practices” method that I am totally missing here?

3 Likes

I recommend running the project with iex -S mix and then, if you want to recompile a single module, use the r/1 function, which takes the module name, rather than a file path.

r(MyApp)
6 Likes

This is exactly the approach that I am using as well, and it works great for me!

I often have two terminal tabs, one where I run IEx and recompile modules when they change to manually test things, and one where I run mix test as well as version control commands to store my changes.

2 Likes

IIRC correctly there is even a package, that does recompile and reload your changed modules. remix and eye_drops might be able to get configured/hacked that way.

2 Likes

Thank you; that is exactly what I need.

2 Likes