Live data from Hacker News

Build a real-time Twitter clone with LiveView and Phoenix 1.5

phoenixframework.org

81–90 of 249 posts

Re: Build a real-time Twitter clone with LiveView and Phoenix 1.5

#81
post #27

Earlier quoted context omitted.

It seems like a lot of companies are moving to Go for fast services. As a rails dev for 10+ years, I am looking at Go instead of Elixir and Phoenix, b/c Go is a much more popular language than Elixir.

Go may be popular, but is also a lot less complete. Some other things to consider are that Go's concurrency model is quite bloated when compared to Elixir's, Go uses public memory for its goroutines vs. Elixir's private memory that protects processes, Go uses cooperative multitasking vs. Elixir's preemptive model, and Go's dependency handling is absolute rubbish. Elixir's process supervision is amazing and Elixir's p…

Which would you say is easiest to learn, for someone with a little programming experience?

I'm currently planning a SaaS project and had settled on go, but this discussion is making me wonder if perhaps Elixir is the better choice.

Re: Build a real-time Twitter clone with LiveView and Phoenix 1.5

#82
post #14

I was a Rails user for almost a decade. I switched to Phoenix/Elixir 3 years ago. Elixir is a super simple language. It has no OO concepts and everything is functions first. In fact, it's so good that I started teaching it for universities. All my production web applications are now fully on Elixir. Elixir is one of those languages where everything has been done perfectly as of the time of this comment. When I say pe…

> And once you start thinking in terms of functions, you just won't touch any of those terrible OO programming paradigms

This sort of absolutism does nobody any favours. Functional zealotry is every bit as bad as OO zealotry.

Re: Build a real-time Twitter clone with LiveView and Phoenix 1.5

#83

Earlier quoted context omitted.

LiveView does not re-render the template on every interaction. LiveView actually sends patches over the wire, which is typically smaller than a hand-written JSON response. The screencast linked above has a good example of this, where clicking the "retweet" button sends a minimal payload, since we know the exact position on the page. LiveView also uses a long-running WebSocket connection and that reduces the amount of…

The patches don't need to be processed by the template engine to render them?

The patches are sent as pure data and a small client-side Javascript library (morph-dom) patches the DOM accordingly, so the template itself doesn't get sent.

Re: Build a real-time Twitter clone with LiveView and Phoenix 1.5

#84
post #75

Earlier quoted context omitted.

There's no magic. It's functionality that's made possible by the BEAM. It's just one of those things that came out of realizing how powerful the runtime was for handling certain types of problems. When you combine a couple of those bits together, you end up with this. The only modern web problem that Elixir isn't ideally suited for is heavy number crunching. Otherwise it gives this amazing balance of efficiency, scal…

I'm of a similar view to them, this felt like lots of magic or at least lots of gotchas I can see myself hitting. I saw two function definition types (def and defp), pattern matching input then requiring a caret for the variable name (?), passing in "assigns" but then referring directly to other variable names, pipes, etc. There's a lot there compared to when I've worked in Erlang.

Gotchas, probably some of those. Both in Elixir and Phoenix. It is an entire language plus an entire web framework.

A lot of people find Elixir more approachable than Erlang. But I wouldn't be surprised if Erlang is technically simpler and as such potentially easier to learn. The syntax is quite foreign to most people coming from more conventional languages while Elixir reads and writes fairly conventionally.

Now Phoenix LiveView does a lot for you, so I wouldn't dismiss the claim of having some magic in there. But once someone starts to get familiar with the stateful approach the model is fairly simple and the "magic" is less mystical. A lot of the things you don't need to pay attention to would be optimizations in markup and templates and how the JS does its job. That's where a bit of magic happens.

Most of the things you mention sound like things about the language. Which I found to be very approachable and the onboarding documentation to be great.

Re: Build a real-time Twitter clone with LiveView and Phoenix 1.5

#85

How would this scale for, I don't know, 10k concurrent users? Would a live chat app be reasonable?

I'd say live chat and many concurrent users (+ many small messages being sent around) is exactly the kind of thing that Phoenix (and LiveView, and Elixir) is basically made for.

Re: Build a real-time Twitter clone with LiveView and Phoenix 1.5

#86

I've been writing code for close to 10 years now and I see this and feel like what a beginner would feel trying to understand assembly code. Or someone hearing a similar but new language. Looks to me hours of work and learning got abstracted as under the hood "magic". It's like saying: Oh, so I've been weight training for the last 17 years and I should tell you Olympic silver is not too hard, see? Am I right in my th…

I think the biggest hurdle would be the Functional Programming aspects. Elixir was quite easy for me to approach coming from mostly PHP, Node.js and Python (preferred Python before Elixir).

Phoenix has a sprinkling of magic or syntactic sugar through macros and stuff but the step between Phoenix and LiveView is not that mystical to me.

I have taught a novice developer, not yet out of 2-year school for web dev, to use Elixir and the Phoenix Framework. I really should interview him about that. Write something up.

I would say that Django does more stuff under the hood than Phoenix. But they are fairly different vehicles.

Re: Build a real-time Twitter clone with LiveView and Phoenix 1.5

#87

Is there a tutorial or course I can purchase like beginner to all the way to deployment on Digital Ocean or something like that ?

FYI, Pleroma is a Mastodon clone written in Elixir with Phoenix, might be good to check it out.

https://git.pleroma.social/pleroma/pleroma

Re: Build a real-time Twitter clone with LiveView and Phoenix 1.5

#88

Earlier quoted context omitted.

> When I say perfect, I mean, there has been never once in my career where I hit a roadblock due to the language's limitation or complexity or flawed assumption. I faced this with other languages, but not Elixir. This is pretty amazing praise! Are many of the other languages you've used strongly typed? That's the thing that gives me pause - I feel like I rely on the compiler a lot in languages where it can do a lot f…

> Are many of the other languages you've used strongly typed? That's the thing that gives me pause - I feel like I rely on the compiler a lot in languages where it can do a lot for me, and that I'd be really frustrated managing a large project without it. As someone who has been writing Elixir professionally for 4-ish years, and who is otherwise about as big of a proponent of static types as is possible, this is simu…

To add to this, it's worth noting that Elixir would have difficulty _ever_ becoming statically typed because of how message-passing works. For example, if you look at Gleam [0] -- the recent project that's trying to create a statically typed language for the BEAM -- it can't handle message-passing [1].

And I totally agree with you here:

> I've found that it's possible to pretend it is a statically typed language if you squint just right.

My Elixir code tends to use a lot of pattern matching on structs. It's not real static typing, but it gets me a lot of mileage!

[0] https://gleam.run/index.html

[1] https://gleam.run/faqs.html#how-is-message-passing-typed

Re: Build a real-time Twitter clone with LiveView and Phoenix 1.5

#89

We are really excited about this release! I also wanted the screencast to be a single take, so I'm happy to answer questions if there are gaps to fill in for things I could have explained more clearly.

Congrats on the launch! I've been following this for a while and played around with it a bit, I'm excited to get my hands dirty with this. How does reconnection work? lets say someone is using the site, and you do a deployment, rolling the nodes over. Does live view simply reconnect to another node without any interruption from the user's perspective?

Confirm. LiveView will apply css loading state classes, which are user defined, but we generated css by default in new apps to lock the UI with loading cursor, and show a top loading bar. On reconnect, which happens automatically, we rematch the DOM with any changes, and we also send up any user form input beforehand so client state is lost that was in progress. We already have reports of users pushing bugs to their systems and the UI seemingly being unaffected because the LiveViews automatically recover, wether from a disconnect or a crash on the server.

Re: Build a real-time Twitter clone with LiveView and Phoenix 1.5

#90

We are really excited about this release! I also wanted the screencast to be a single take, so I'm happy to answer questions if there are gaps to fill in for things I could have explained more clearly.

Congrats on the launch! I've been following this for a while and played around with it a bit, I'm excited to get my hands dirty with this. How does reconnection work? lets say someone is using the site, and you do a deployment, rolling the nodes over. Does live view simply reconnect to another node without any interruption from the user's perspective?

[deleted]
Post reply on HN