Live data from Hacker News

Elixir and Phoenix after two years

nts.strzibny.name

41–50 of 111 posts

Re: Elixir and Phoenix after two years

#41
post #37
post #3

To add to the author's experience, I spent 18 months of production time with Elixir and Phoenix. As he says, the templates are compiled and are blindingly fast compared to Rails. Pattern matching is really really nice when used in the right places (and you'll miss it if you go back to Ruby); but it can be overused. There's a faction of Elixir folks who attempt to avoid all conditionals and instead seem to prefer mult…

> Sometimes simply reading a switch statement or if/else/then is much clearer Case statements are pretty common, and for code I read the with statement[1] is even more common. This allows you to code a happy path broken into small steps and then collect your edge cases. It doesn't solve every case for if/else or cases, but it's a nice tool. [1] https://hexdocs.pm/elixir/Kernel.SpecialForms.html#with/1

I love with, completely forgot to mention it.

Re: Elixir and Phoenix after two years

#43
"Elixir is not an object-oriented language. We practically only write modules and functions. This helps tremendously in understanding code..."

Sign me up. I hold hope that Elixer is the thing that starts pushing the knife into OOP. Microsoft has added a ton of features to make functional style a thing in C#, and nearly everyone hates Java...so maybe the stars are aligning.

Re: Elixir and Phoenix after two years

#44
post #36
post #4

Earlier quoted context omitted.

It's pretty great anywhere that you might use Rails or Django, but if you expect spike in traffic that are hard to predict you get nice stable worst case latency. I think it's also really good if you need to hold state server side for any reason.

Rails has a ton of high quality code available for it. It looks to me like Phoenix is certainly 'good enough' for a lot of tasks, but it just hasn't been around as long. I'm looking for those use cases where someone picked Phoenix and it was just clearly a better tool than, say, Rails because of X, Y, and Z, despite maybe being inferior for one or two other things.

Having done both, I think Rails has a ton of baggage around ActiveSupport and ActiveRecord that are full of gotchas. Ecto prevents N+1 queries by default, which I think is clearly better. I also think that the lack of lifecycle hooks in Ecto is a better decision than the pile of foot guns in ActiveRecord hooks.

I would also argue that Plug is a large improvement over Rack, and the idea of explicitly passing a single context map all the way through the request is just a better way to build http responses. I also think that the Fallback controller is obviously a better way to handle common errors.

Anything related to web sockets will be leagues better in Elixir, because the BEAM is built to do a thing like that.

SSR html as a compiled linked list is a better idea than runtime string interpolation.

Sure, Rails has libraries for everything, but some of the core parts just aren't a nice. So if you don't need all of that breadth of ecosystem then Phoenix is a better choice IMHO having worked professionally with both for a number of years.

Re: Elixir and Phoenix after two years

#45
post #2

What are people finding as the real sweet spots for Phoenix? I have used Erlang very successfully in a semi-embedded context, but that's quite different from a web server that can usually be scaled horizontally pretty easily. One obvious one is if you have to hold open a lot of concurrent connections like web sockets. It'd be great for that. Others?

Fast templates are a superpower for our CMS. Combine it with LiveView to eliminate react and we deliver a really good site quickly.

Re: Elixir and Phoenix after two years

#46

I wish more Node.js people shake off their Stockholm syndrome and check out Elixir and Phoenix.

Let me tell you the single reason I haven't switched to Elixir yet: I develop backend and frontend (SPA) so I'd rather just stick with a single language and library catalog. It helps that there's plenty of libraries in JS land too. I would love to just write elixir code but at the end of the day I feel sticking with node+browser js is the more pragmatic choice right now.

Re: Elixir and Phoenix after two years

#47
post #3

To add to the author's experience, I spent 18 months of production time with Elixir and Phoenix. As he says, the templates are compiled and are blindingly fast compared to Rails. Pattern matching is really really nice when used in the right places (and you'll miss it if you go back to Ruby); but it can be overused. There's a faction of Elixir folks who attempt to avoid all conditionals and instead seem to prefer mult…

> and perhaps there could be a more concise enhancement of Erlang which would get the job done Erlang already is a more concise language than Elixir but also noisier as there are more punctuation characters. I would love if Erlang would drop some of its punctuation, as some of it is frankly unnecessary. Elixir syntax is definitely simpler than Ruby’s. Probably in the same ballpark as Python complexity wise: Elixir ha…

> Erlang already is a more concise language than Elixir but also noisier as there are more punctuation characters.

What?

Here's more-or-less the entirety of Erlang's "noisier syntax with more punctuation characters"

  -spec f(A :: any(), B :: some_type(), C :: list()) -> any().
  f(A, {B}, [C | _]) ->
    A1 = fun() -> io:format(a, []) end,
    A1(),
    case C of
       > -> 1;
       _ -> #person{ok = ok, field = C}
    end.
Edit:

  %% plus map syntax

  #{"tuple" => {1,2}}
  M#{"key" := "new_value"}

  %% plus list comprehensions

  [X || X 
Elixir has all that plus more. The equivalent in Elixir is something along the lines of

  @spec f(a :: any(), b :: some_type(), c :: list()) :: any()
  def f(a, {b}, [c | _]) ->
    a1 = fun() -> IO.inspect(a) end,
    a1.(),
    case C do
       > -> 1
       _ -> %Person{ok: :ok, field: c}
    end
  end

  ## and don't forget the capture and pipe syntax
  
  x |> (&f(y, {&1}, list)).()

  ## and default function parameters

  def f(a, b, c \\ []), do: something()

  ## and sigils

  String.replace(str, ~r".*", "")

  ## and Ecto adds its own characters

  id = 1

  (from p in Person, where: p.id == ^id, select: p) |> Repo.all()

  ## and dropping down to Erlang is a function call on an atom

  :io.format(x, y)

And I'm definitely forgetting more...

Edit:

  ## and string interpolation

  a = 1
  
  s = "The value is: #{a}"

  ## and two different map syntaxes

  %{a: :map, with: "various", keys: "as", atoms: 0}

  %{"another" => "map", "but" => "keys", "are" => "strings"}

  ## and different map access

  map[key]

  map.key

  ## and map update

  %{ map | key: "new_value" }

  ## and list comprehensions

  for x 

Re: Elixir and Phoenix after two years

#48
post #2

What are people finding as the real sweet spots for Phoenix? I have used Erlang very successfully in a semi-embedded context, but that's quite different from a web server that can usually be scaled horizontally pretty easily. One obvious one is if you have to hold open a lot of concurrent connections like web sockets. It'd be great for that. Others?

We used Elixir to implement a columnar database and Phoenix for the web front end, which was about 20% of the code. It’s very convenient having all the tests run together, including end to end integration tests. Elixir (with NIFs) has the necessary performance for the database layer, and Phoenix has the necessary productivity for the web layer, and we don’t have to switch languages to work on both.

Re: Elixir and Phoenix after two years

#49
Big fan of Elixir. First and third party libraries are typically very high quality; community support is great; and documentation is best in class.

Right now, I’m trying to find a way to speed up builds in CI because they’re the biggest bottle neck to deploying. Building an umbrella with 5 apps, 3 of which are phoenix, leveraging parallelised docker buildkit, will still take 8~ minutes.

Re: Elixir and Phoenix after two years

#50
post #11

Earlier quoted context omitted.

In terms of language, Phoenix is a complete replacement for Rails for me. I feel more comfortable growing a functional codebase, and the BEAM means I don't have to worry about scaling as soon as I would with Rails. I think it's a good fit for when you want to do more with a small, experienced team. I would reach for Rails when I'm concerned about finding developers (Elixir devs are fewer and more expensive, generally…

I fear it would be difficult to hire Elixir people as well, but now I realize it's actually also hard to hire decent Ruby/Rails people. Honestly I think we should just accept anyone who can demonstrate thinking and programming skills of any language and then plan for 2-3 months of ramp-up time to get them into our language of choice.

I'd be happy (if I were job-hunting) to be able to try out a different language/platform every so often. Now and again I'll play with, say, Ruby or Elixir or whatever. But I know that I'll never get a job working with these languages because I don't have the n years experience with them. The tech hiring process is gruelling enough with languages and frameworks we are familiar with, your resume won't even get a glance if you apply for jobs where you don't have that experience. But I think that narrow thinking is to everyone's detriment.
Post reply on HN