Live data from Hacker News

Learning Elixir: My side-project

adrian-philipp.com

31–38 of 38 posts

Re: Learning Elixir: My side-project

#31
post #21

I think what I learned the most about my past year of working heavily in Elixir is this.. Don't learn elixir.. learn Erlang/OTP if you really want to harness the power of Elixir. Elixir is nothing but a series of macros which give erlang some convenience and better syntax. If you learn to harness the power of Erlang, while writing it in Elixir, then you will see the beauty of it. Get away from Phoenix as fast as poss…

I learned Phoenix and OTP at basically the same time. I knew I'd need to build out a worker queueing system as part of a web app, so I started reading an OTP book while I was building the initial structure of the Phoenix app. By the time I needed to do more interesting things than just a crud app, I could work with GenServers and Supervision trees.

The moment that the lightbulb went on for me was when I ran `iex -S mix` in my Phoenix project and fired up erlang's observer to see its processes. I realized that phoenix is just a supervision tree made up of different microservices, much more complicated than the toy projects I'd built, but still relied on the same OTP tools and patterns. And once you understand that, it becomes trivial to use OTP to expand the functionality that Phoenix gives you out of the box.

I think what you're trying to say (and I agree if you are) is that Phoenix and Elixir are great, but you are missing out on what makes Elixir so powerful (Erlang/OTP and BEAM) if you stop there.

Re: Learning Elixir: My side-project

#32
post #21

I think what I learned the most about my past year of working heavily in Elixir is this.. Don't learn elixir.. learn Erlang/OTP if you really want to harness the power of Elixir. Elixir is nothing but a series of macros which give erlang some convenience and better syntax. If you learn to harness the power of Erlang, while writing it in Elixir, then you will see the beauty of it. Get away from Phoenix as fast as poss…

I do Erlang full time. But seeing how much traction Elixir has, I say learn whatever looks more interesting. If you're developing for the web and Phoenix looks good, start with Elixir.

At the end of the day, they are both built on the same foundational concepts. You might find that you need to look up Erlang docs or find an Erlang SO answer so might as well learn the basic Erlang syntax as well. Then you have access to a larger community. Listen to Erlang Factory or Joe Armstrong's videos and so on.

Re: Learning Elixir: My side-project

#33
I picked up Elixir and LFE (Lisp Flavoured Erlang) at the same time. I prefer Lisps, and so I stuck with LFE, so my knowledge of the current state and capabilities of Elixir is lacking. Robert Virding who co-created Erlang, created LFE. He responded to Jose Valim in 2013 in a LFE vs Elixir thread [1].

I was accused of spreading misinformation when I made the same point recently on HN in another Elixir thread [2].

So my question is: Does Robert Virding's point still hold about Elixir's macros only able to use its predefined syntax, and not create new syntax like a Lisp can. I like Elixir, I just prefer Lisp's syntax. However, if Elixir is making these type of improvements I may want to revisit it, and to ensure I am not repeating old, incorrect information.

Robert Virding uses this example (look at the thread for context):

>> (defmacro kl >> ((list* k v rest) `(cons (tuple ',k ,v) (kl ,@rest))) >> (() ()))

>> which I can use

>> (kl a (+ 2 7) b 6) ==> (#(a 9) #(b 6))

Can Elixir do this or not?

Thanks!

  [1]  https://groups.google.com/forum/#!topic/lisp-flavoured-erlang/ensAkzcEDQQ
  [2]  https://news.ycombinator.com/item?id=14390916

Re: Learning Elixir: My side-project

#34
post #33

I picked up Elixir and LFE (Lisp Flavoured Erlang) at the same time. I prefer Lisps, and so I stuck with LFE, so my knowledge of the current state and capabilities of Elixir is lacking. Robert Virding who co-created Erlang, created LFE. He responded to Jose Valim in 2013 in a LFE vs Elixir thread [1]. I was accused of spreading misinformation when I made the same point recently on HN in another Elixir thread [2]. So…

Yes, sorta.

The point I think he was trying to make was that Lisp's syntax is less restrictive, but that seemed to get confused by:

- mentioning the some people say it has no syntax (which it definitely does have)

- saying macros can create new syntax (which they can't in Lisp)

Elixir macros are approximately the same as Lisp macros (apart from not being able to take a variable number of arguments).

This is a straight port of that macro into Elixir:

  defp kl_i([k, v | t]) do
    quote do
      [
        {unquote(Macro.escape(k)), unquote v}
        | unquote kl_i t
      ]
    end
  end
  defp kl_i([]), do: quote do: []
  defmacro kl(l), do: kl_i l
  
  # usage
  IO.inspect kl [a, 2 + 7, b, 6]
  # => [{{:a, [line: 16], nil}, 9}, {{:b, [line: 16], nil}, 6}]
Note: Elixir's syntax does get in the way a bit here, the `a` and `b` are converted into nullary calls, you could use a different escaping function to fix this

  defp escape_key({v1, v2}), do: {escape_key(v1), escape_key(v2)}
  defp escape_key({:{}, pos, els}) when is_list(pos), do: {:{}, pos, Enum.map(els, &escape_key/1)}
  defp escape_key(els) when is_list(els), do: Enum.map(els, &escape_key/1)
  defp escape_key({sym, pos, nil}) when is_list(pos), do: Macro.escape sym

Re: Learning Elixir: My side-project

#35
post #33

I picked up Elixir and LFE (Lisp Flavoured Erlang) at the same time. I prefer Lisps, and so I stuck with LFE, so my knowledge of the current state and capabilities of Elixir is lacking. Robert Virding who co-created Erlang, created LFE. He responded to Jose Valim in 2013 in a LFE vs Elixir thread [1]. I was accused of spreading misinformation when I made the same point recently on HN in another Elixir thread [2]. So…

Yes, sorta. The point I think he was trying to make was that Lisp's syntax is less restrictive, but that seemed to get confused by: - mentioning the some people say it has no syntax (which it definitely does have) - saying macros can create new syntax (which they can't in Lisp) Elixir macros are approximately the same as Lisp macros (apart from not being able to take a variable number of arguments). This is a straigh…

I sort of get it. But this part he writes in the discussion seems to hold, no?

"What I mean here is that elixir has a predefined syntax. It has a number of predefined syntactic constructs, operators and function calls. And while I can with macros change the meaning of the constructs I cannot add new constructs or operators as the handling of macros is done after parsing. So if I want to add something completely new it ends up syntactically being a function call. Now elixir has many ways of disguising function calls at the end of the day they are syntactically still function calls. For example parentheses around arguments are optional, there is special syntax for property lists where the keys are all atoms, special syntax for using these property lists as function arguments, special handling of do ... end when it is a function argument, etc. Elixir's uniform abstract syntax makes it easier to work with these but I am still limited by only having the existing syntax."

Re: Learning Elixir: My side-project

#36
post #21

I think what I learned the most about my past year of working heavily in Elixir is this.. Don't learn elixir.. learn Erlang/OTP if you really want to harness the power of Elixir. Elixir is nothing but a series of macros which give erlang some convenience and better syntax. If you learn to harness the power of Erlang, while writing it in Elixir, then you will see the beauty of it. Get away from Phoenix as fast as poss…

I learned Phoenix and OTP at basically the same time. I knew I'd need to build out a worker queueing system as part of a web app, so I started reading an OTP book while I was building the initial structure of the Phoenix app. By the time I needed to do more interesting things than just a crud app, I could work with GenServers and Supervision trees. The moment that the lightbulb went on for me was when I ran `iex -S m…

Yep, that's exactly it. I'm just not very eloquent ;)

Re: Learning Elixir: My side-project

#37
post #30
post #21

I think what I learned the most about my past year of working heavily in Elixir is this.. Don't learn elixir.. learn Erlang/OTP if you really want to harness the power of Elixir. Elixir is nothing but a series of macros which give erlang some convenience and better syntax. If you learn to harness the power of Erlang, while writing it in Elixir, then you will see the beauty of it. Get away from Phoenix as fast as poss…

How does Phoenix detract from from the elixir/erlang experience? I was under the impression that it was just a web framework? I'm pretty naive on the subject—I've just never seen something like this brought up before.

Well in my situation Phoenix is really overkill. I don't build monolithic apps anymore. To me Phoenix felt lake taking Ruby and slapping it on Elixir. It didn't really feel like, "The Elixir Way." So I set out and learned Plug(which is mostly what Phoenix is).

I build all my front ends as stand alone ReactJS apps, so I found it very strange to need Phoenix at all. I started learning to work with OTP & Plug and realized that I can build a json-api spec API in complete Elixir without any phoenix requirements and if I need to add sockets it's very very trivial to do so.

The amount of code needed to make this all work in pure elixir is minimal.

Essentially I just didn't need it for the way I build applications these days.

Re: Learning Elixir: My side-project

#38
post #37
post #30

Earlier quoted context omitted.

How does Phoenix detract from from the elixir/erlang experience? I was under the impression that it was just a web framework? I'm pretty naive on the subject—I've just never seen something like this brought up before.

Well in my situation Phoenix is really overkill. I don't build monolithic apps anymore. To me Phoenix felt lake taking Ruby and slapping it on Elixir. It didn't really feel like, "The Elixir Way." So I set out and learned Plug(which is mostly what Phoenix is). I build all my front ends as stand alone ReactJS apps, so I found it very strange to need Phoenix at all. I started learning to work with OTP & Plug and realiz…

That makes sense. I was under the impression that you were saying something along the lines "Phoenix breaks erlang," but the complaint that Phoenix is too bulky is pretty common.
Post reply on HN