Experience with Elixir in comparision to R - how to develop without something like RStudio?

Hello,

In the last several months I tried to learn Elixir and Phoenix. Thanks to some good learning material I think I have learned the basics.

I have some experience with some other programming languages, mainly Java and R. Both have an exceptional IDE (intelliJ and RStudio) which support me a lot in my daily routines (commands on cli, debugging, etc.).

While I feel it is not so hard to think in functional programming (coming from an OOP background), it is very hard for me to program “blindly” in Elixir. In RStudio I can always see and inspect all the variables in memory so I can step through my code line by line and see how it changes my variables. My approach to programming is trial and error: I write a new line of code, try it (in most cases by using breakpoints and then inspect my variables, but in RStudio you also can execute just a selected line) and when it does what I wanted it to do I move to the next line…

I miss this extremely when I am developing with Elixir so I guess I’m doing it wrong. What is the right approach with Elixir? Writing testing functions? Are there any guides/tutorials for this?

The books I know show and explain what is the correct code, but not how to come to it. Hopefully you can understand what I mean. It is not so easy to explain…

1 Like

Have you happened to use the pry feature in elixir ? and also try to use observer which provides certain monitoring facilities…

This thread here is very much related to this:

Also, this uses Visual Studio Code, that provides some GUI comfortability:

https://elixirforum.com/search?q=visual%20studio

There are various plugins for Vim, Atom, etc., please do check the elixir-lang official site for supported editors.

Thanks.

2 Likes

Welcome to the community :023:

We have a few options - tho many are not a full blown IDE they come pretty close :smiley:

First, you may find this poll interesting:

And here are some other threads of interest:

And a few more at the code-editors tag.

On the Elixir website there is also a list of code editor support with install instructions :smiley:

CODE EDITOR SUPPORT

I’d recommend trying a few and seeing which one you prefer, and if you run into any issues or have any other questions just let us know :smiley:

2 Likes

I was afraid of being misunderstood by not being able to explaining my situation properly…

I am not so much looking for an IDE. I know that there is not some thing as RStudio.

I wanted to know how people program in Elixir. Do they know exactly that every code line is correct so that they do not need to see the variables’ values at any time? No need to debug?

I will have a look at ‘pry’, thanks.

2 Likes

It is not usual to follow variables changes because variables are immutable.

You might get used to sequential coding, but it’s more

input -> function -> output

or more like a pipeline of transformation… like

output = input
|> apply_change1()
|> apply_change2()
|> apply_change3()

In that case, You can insert some inspect/1 in the pipeline to see how data changes.

2 Likes

@Rolling Welcome to the forum!

When I start writing a function and I want to experiment I usually do the following :

start an iex session: iex -S mix, alias Project.Module the modules I’m using so that I don’t have to write the long names every time I’m just use Module to refer to them

Whatever operations I wanted to do inside the function I try them in the console one by one, check that they work as expected or fix them

To get the values from a specific expression I usually do:

iex (5)> 2+2
4
iex (6)> var = v 5
4

and if I change a module I need to load it again: r Module in order to be able to call the updated functions

1 Like

I always write the tests and use IO.inspect/2 either in the code or the test to see the value passed in. This is my own variant of TDD. Instead of red-green-refactor, I write enough in my test code (sometimes without assertion) to execute the code I am writing, and use mix test.watch to run the test so that I can see the value.

Personally, I enjoy this way of writing code compared to using iex -S mix. When I am done with the code, I will end off my test with the assertions to check everything is working correctly.

1 Like

TDD is definitely how I approach it. If you’ve not used it before this mini series from Kent Beck is a great introduction (not elixir but easy to follow) https://vimeo.com/10789674