News for hackers. Stuff that matters.
Re:Back-end languages are coming to the front-end by kuon on Thursday February 10, 2022 @11:03AM (#30288110)
I just shipped my fourth large project based on Phoenix LiveView and I think it is the best thing that happened to web dev since forever.

The javascript is minimal (like to manage selection in text field or to handle copy/paste). Everything else is in elixir. Tailwind is used for CSS.

Having the full client state available on the backend is really incredible. It is so much easier, no more ajax/graphql... You just have all your backend data "under your fingers".

I can only recommend giving it a try.

Also, if your app is offline first, phoenix channels are great for sync. It is not live view, but it is easier to use than ajax calls.

Re:Back-end languages are coming to the front-end by igammarays on Thursday February 10, 2022 @01:33PM (#30290485)
> Having the full client state available on the backend is really incredible.

Got the exact same feeling writing my latest app with Laravel Livewire. The ability to use backend state seamlessly on the frontend without explicitly passing state back and forth reduces complexity so much it's like writing 1 application instead of 2. I was able to build rich, fully interactive apps with minimal JS -- I'll never go back to React again.

Re:Back-end languages are coming to the front-end by jon1628492 on Thursday February 10, 2022 @11:29AM (#30288561)
A question from a newcomer to the ecosystem: do you have any recommendations for an admin system like Django's? On a related note, how do you usually determine whether a package is abandoned vs stable?
Re:Back-end languages are coming to the front-end by dnautics on Thursday February 10, 2022 @01:04PM (#30290101)
The crazy thing is that most elixir packages that are abandoned still basically work. This is both a blessing and a curse all around
Re:Back-end languages are coming to the front-end by vasergen on Thursday February 10, 2022 @02:33PM (#30291299)
out of curiousity, how difficult to support large project in elixir, especially refactoring, giving there is no static typing. I know about pattern matching, which helps, but interesting to hear practical experiance
Re:Back-end languages are coming to the front-end by kuon on Thursday February 10, 2022 @05:27PM (#30293588)
In practice, there are two things:

- crash on error - functions are just functions

The first one is counter intuitive to many programmer. Basically you use pattern matching aggressively, like this:

    def full_name(%{first_name: <<a::utf8, _::binary>>, last_name: <<b::utf8, _::binary>>}) do
      "#{a} #{b}"
    end
This code will work only if a map/struct with the correct non null field are passed. The pattern match utf8 string of at least 1 valid utf8 character. Any other argument will crash.

Crashing in elixir is the way to handle unexpected things. For example, you will do:

    {:ok, myobject} = DB.get....
And if the DB fails (something unexpected), it will crash, the process will be restarted and the live view connected remounted and it will start again from a clean state.

Of course, error that are expected should be handled.

The second thing with elixir, is that functions are decoupled from data. You can move them around easily. For example, the above function will work on any struct with the correct fields and a plain map. But you can pattern match on specific struct too, which makes the code more like OOP, but it is more rarely done.

The key idea is to restrict code paths to something you expect, and always be explicit about what to expect.

Re:Back-end languages are coming to the front-end by aej on Friday February 11, 2022 @08:28AM (#30301199)
When it comes to refactoring, the fact that Elixir is compiled helps a lot - there are a set of mistakes you make during a refactor which the compiler will just catch for you.