What is your number one tip for anyone new to Elixir?

From me, it’s to learn about the equals sign = first. It isn’t the assignment operator as you might expect!

It can do assignment, but it can do a lot more too! Think of it more like the equals sign you learned about in your maths lessons - where the formula on both sides actually match by ending up being equal, for example, a = b + 3 if you know the value of a you can work out the value of b, and if you know the value of b you can work out the value of a. This allows you to do stuff with the values when they do, or don’t, match.

Programming Elixir has a really good section on this :slight_smile:

8 Likes

Be patient and focus on fundamentals, that’s what I’m doing currently.

5 Likes

A few things

  1. Use i in iex
  2. Use of .iex.exs
  3. Use of inspect and IO.inspect
5 Likes

The importance of reading error messages and stacktraces.

16 Likes

New to Elixir, but not programming:

Processes execute in a single thread.

For me, this has huge ramifications for concurrency. No need for slapping on a mutex or critical section, etc. If you’re dealing with a resource that would require locking, then very likely you should have a process that governs that resource. The BEAM can do millions of processes, but each one will execute in a single thread. Amazingly elegant. :smile:

New to Elixir and programming:

Use double-quotes " for strings.

Single-quoted char lists are for interfacing with Erlang libs.

5 Likes

1 Read the docs

If their is any number two advice

it is

2 Repeat first

5 Likes

Learn OTP and distribution well.

3 Likes

1 learn syntax
2 learn plug
3 learn ecto
4 enjoy phoenix and nerves

2 Likes

Elixir processes are single-threaded event loops.

2 Likes

Is this strictly true? GenServers have receive loop but nothing obligates a process to ever check its mailbox.

1 Like

OTP, Supervisors, Genservers etc. are great… but you don’t NEED to be fluent in them to write your first production application. If you write a Phoenix application, for instance, basic supervisors are already taken care of for you.

(I feel like a lot of talks focus on these topics, and they are great and interesting and mind expanding but can be intimidating to newcomers especially)

2 Likes

It is not strictly true. But in a way yes.

1 Like

Start bulding and learn as you go. It’s easier to start with one thing first, then trying to go for it all (goes for many things in life as well) :slight_smile:

3 Likes
  1. Read info/tutorials/docs and other linked sources available in official site.
  2. Search at this forum for categories and threads that you are interested in. Be sure to check also our wiki tag.
  3. If you don’t understand something then don’t feel stressed to ask here, you are welcome :smile:.
  4. Universal tip: Try always plan your free time
  5. Read other projects
  6. Start from something simple, don’t try to modify elixir source, but if you have idea then feel free to write in this thread.
  7. Use forum or other communication sites for developers before creating issue(s).
    If you find a bug then be sure to check it twice and create an issue with good description (list to reproduce your problem).
  8. Read forum every day - we are creating lots of interesting threads! :smile:
  9. If you can create some basic apps then work at your code style.
    We already have lots of tips that suggest you how to write a clean code:
    A community driven style guide for Elixir by @christopheradams
    Style Guide for the Elixir language, implemented by Credo by @rrrene
    and last, but not least: An opinionated Elixir style guide by @lexmag (used by core developers)
  10. Use tools to easily manage your code. I suggest you Atom editor and it’s packages (also for Elixir).
    Credo which style guide I already mentioned is also really helpful.

Help yourself, help others, ask and answer questions - live and forgot about brutal world (at least to midnight :077:).

1 Like

Add Beauty to the code

The FIrst Immediate thing is stop using the functions out put like this
final(Math.round(getValue(x)))
That Looks Really Weird to read and understand what is happening here

getValue
|> Math.round
|> final

:slight_smile:
Did you see how the beautiful the code looks
Start using the Pipe |> operator, this where the Elixir differ and stand unique besides the light weight Process Mechanism.

2 Likes

For me, it was to remember to use pattern matching! At first, I was using lots of if/else clauses and equality tests, because that was what I was used to. Many programmers will come from languages without pattern matching (or at least with much less powerful pattern matching).

e.g. I like this example from an Exercism solution:

  @doc """
  Return the kind of triangle of a triangle with 'a', 'b' and 'c' as lengths.
  """
  @spec kind(number, number, number) :: { :ok, kind } | { :error, String.t }
  def kind(a, b, c) do
    case Enum.sort([a, b, c]) do
      [x, _, _] when x <= 0 -> { :error, "all side lengths must be positive" }
      [x, y, z] when x + y <= z -> { :error, "side lengths violate triangle inequality" }
      [x, _, x] -> {:ok, :equilateral}
      [x, x, _] -> {:ok, :isosceles}
      [_, x, x] -> {:ok, :isosceles}
      _ -> {:ok, :scalene}
    end
  end
5 Likes