i-n-g-m-a-r

i-n-g-m-a-r

A %Phoenix.LiveView.Socket{} is not a %Phoenix.Socket{} yet both are called socket.
Would it be better to call a Phoenix.LiveView.Socket struct a live_socket ?

Showing Posts 1 to 10

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Names are always contextual. In the context of a live view module the %Phoenix.Socket{} is never accessible, so you don’t need to distinguish the live socket you have from an ordinary phoenix socket. In a similar way, we always refer to a %Plug.Conn{} as conn even though there is also a cowboy connection out there making the request work. The cowboy connection isn’t really accessible in the context of a plug, so conn has plenty of context and there’s no ambiguity.

i-n-g-m-a-r

i-n-g-m-a-r OP

To interpret contextual names it’s necessary to be aware of the particular context which is not always easy when there’s many contexts and you’re not actually working on the module you’re looking at.
When names are self explanatory there’s no need to figure anything out.
Explicitness really is the only thing Python has over Elixir in my opinion.

sb8244

sb8244

Author of Real-Time Phoenix

I’m going to agree with @benwilson512 here. The point of not exposing lv_socket vs phx_socket is that it doesn’t really matter in the LiveView itself. As a public consumer of LiveView, you shouldn’t need to worry about what the Socket is. If Phoenix wanted to swap out the implementation of Socket completely, they could do so and it wouldn’t affect you.

Phoenix itself does distinguish between the types of sockets. You can find an example in the LiveView source code. I think this is interesting because it shows that explicitness is being prioritized where important, and removed where it’s not important. If you are curious about how the sausage is made, then the source code is very accessible. This is a very pragmatic approach, imo.

It would be helpful to have more examples here. I’ve generally felt like Elixir as a language is really explicit. Libraries like Phoenix are good stewards of quality code, as well.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

What concrete problem are you running in to?

i-n-g-m-a-r

i-n-g-m-a-r OP

To me live_socket would expose that I’m looking at a live view.

Another example could be:

which is about assigns vs conn (.assigns)

i-n-g-m-a-r

i-n-g-m-a-r OP

The concrete problem is that I sometimes loose track of what is what.
For example today I was doing something like:

Phoenix.LiveView.live_render @conn,
  MyLiveView,
  looks_like_assigns: "but should be one of [:session, :container, :id, :router]"

And then I don’t get any feedback saying looks_like_assigns will never work,
probably you mean something else.
(of course I should read the docs better)

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Can you elaborate on how that connects to socket variable name conventions?

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

To address what feels like a different topic, live_render having different args than render, I think a PR validating the options to live_render would be a great addition. It’s still very much a work in progress.

i-n-g-m-a-r

i-n-g-m-a-r OP

Well that example doesn’t.
I was trying to give an example of explicitness that would help.
With regard to socket variable name conventions many times I will pass sockets to helper modules that aren’t using Phoenix.LiveView.
Then, when I want to assign things, I would call Phoenix.LiveView.assign directly.
Which doesn’t work when it’s not a live socket.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Right, if I have a module that has helpers and some are for live view and some are not, then in THOSE functions I would have the variable be named live_socket. The context of the helpers is different from the context of a live view module. The caller of a function and the function argument don’t need to be exactly the same name. Type specs can be very helpful there too.

Where Next? Top

Trending in Discussions Top

budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
axelson
Hi there! :wave: @frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
achempion
I’ve been using Emacs as my main code editor for more than a two years. It’s a custom build version although I’ve tried doom emacs and sp...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
jtormey
Lately I’ve been thinking about how to organize components as a LiveView application grows. One of the pain points I’ve found (for myself...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New

Other Trending Topics Top

KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
kip
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews