i-n-g-m-a-r
Argument/variable naming: Phoenix.Socket vs Phoenix.LiveView.Socket
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 ?
Most Liked
benwilson512
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.
benwilson512
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.
Popular in Discussions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








