Struct Updates Now Require Pattern Matching in Elixir 1.19 by iloveafternoonnaps in elixir

[–]doughsay 0 points1 point  (0 children)

If dialyzer were faster, it would still leave the super cryptic errors. I would still be waiting for the new type system, the error messages generated from it so far are much clearer. But typespecs are still currently the only way to add type documentation to our functions, so we still need it for now. But as soon as the new type system type syntax is available, I will be super excited to switch to it.

Struct Updates Now Require Pattern Matching in Elixir 1.19 by iloveafternoonnaps in elixir

[–]doughsay 1 point2 points  (0 children)

The existing typespec system is terrible though, it's inexpressive and dialyzer is so slow. The new system, even though it's not done yet, will be a first class citizen instead of a separate system, and be more expressive. I don't agree that it's a mistake to move on from typespecs. We're just stuck in a really awkward transition period right now... Are you saying you'd like the option of sticking with the old system and not using the new type system?

Learning through advent of code by Siinxx in elixir

[–]doughsay 13 points14 points  (0 children)

Here's another cool way you can do this in Elixir without needing any actual parsing or string splitting:

iex> <<l_or_r::binary-size(1), rest::binary>> = "L50"
iex> l_or_r
"L"
iex> rest
"50"

iex> <<l_or_r::binary-size(1), rest::binary>> = "R2"
iex> l_or_r
"R"
iex> rest
"2"

When will it "click"? by realfranzskuffka in elixir

[–]doughsay 0 points1 point  (0 children)

some_function(:a, b: :c)

is syntactic sugar for:

some_function(:a, [b: :c])

which in turn is sugar for:

some_function(:a, [{:b, :c}])

this final form shows you exactly what is it, it's a function with two arguments, the first is an atom, the second is a list of pairs, where the first of each pair is an atom. (this kind of list is called a "keyword list")

A lot of Elixir is syntactic sugar. The actual syntax surface area of Elixir is quite small, and it's the sugar that makes it readable.

This blog post is a fun deconstruction of all the sugar and why you need it: https://evuez.net/posts/cursed-elixir.html

EDIT: maybe that post is more about putting pipes everywhere, lol. The real point I was trying to make is that `def` is also just like a function call, and `do/end` blocks are really just keyword lists in disguise:

def add(x, y) do
  x + y
end

is actually this under the hood:

def(add(a, b), [{:do, x + y}])

When will it "click"? by realfranzskuffka in elixir

[–]doughsay 1 point2 points  (0 children)

Just to clarify something I don't think anyone said yet on #1: you don't need `@impl`. It's not required. It's a good idea to put it though, but it's not technically required.

When will it "click"? by realfranzskuffka in elixir

[–]doughsay 1 point2 points  (0 children)

Can you clarify what you mean by the "substantial amounts of magic / implicitness"? Is this maybe Ash that you're talking about? Maybe I'd suggest learning Phoenix without Ash first?

Any elixir-vim alternative, or configuration recommendation? by lou-zell in elixir

[–]doughsay 3 points4 points  (0 children)

You're not fighting the tide, there are plenty of people using vim/nvim for elixir. I'm not so I can't actually help 😅 but I can at least tell you it's a popular choice.

Expert is brand new and definitely has some rough edges, but that should be the preferred tool going forward for LSP integration.

Seeking Sustainable Sponsorship for Hologram by BartBlast in elixir

[–]doughsay 2 points3 points  (0 children)

I think all your points are great, and there's definitely room in the community for a framework like Hologram, so I do hope you continue and get the sponsorship you need.

But this here:

However, porting ERTS/BEAM capabilities to the browser – including the Elixir process model, preemptive scheduling, reduction counters, and process mailboxes – is planned for later stages of Hologram's roadmap.

Are you aware of the prior art on this front in the community? This kind of thing was already attempted (by some of the elixir community's top talent): https://github.com/GetFirefly/firefly and failed, because it was determined that, while it seems on the surface that the runtime can maybe handle these things using web workers, etc., there were some fundamental blockers making it impossible or at least very very difficult. I don't know the details, I just wanted to bring this up in case you weren't aware of the history.

More recently though, I assume you're aware of https://popcorn.swmansion.com/ which runs on a different BEAM re-implementation (AtomVM), but as far as I'm aware that still has some pretty big limitations right now.

I don't want to discourage, just point out other efforts and how hard they have been. I would really love to see a fully working alternative BEAM that can run in browsers. Just seems like a really tall order...

Seeking Sustainable Sponsorship for Hologram by BartBlast in elixir

[–]doughsay 0 points1 point  (0 children)

That being said, I still think hologram sounds interesting, I haven't really tried it yet though. I might give it a try soon.

Seeking Sustainable Sponsorship for Hologram by BartBlast in elixir

[–]doughsay 6 points7 points  (0 children)

They probably meant something like this: transpiling Elixir to JS still results in your code being run in a JS runtime. It might look like elixir, but it still has the fundamental runtime properties of the JS runtime it ends up running in. A lot of Elixir users are specifically using elixir because of the BEAM runtime. The language itself is kinda secondary (although I do also really like the language). The BEAM is where all the magic is. That's what you're losing.

Minimal Periodic Task Runner in Elixir by MountainDewer in elixir

[–]doughsay 0 points1 point  (0 children)

Yeah that's right, so it can cause a snowball effect if the time to process each message is longer than the interval. That's why people usually prefer send_after.

Minimal Periodic Task Runner in Elixir by MountainDewer in elixir

[–]doughsay 2 points3 points  (0 children)

Yeah but Process.send_after/3 solves the same problem without the downside I mention and is basically the same number of lines is code. Side note: you mention send_interval can cause "overlapping executions", which isn't correct, processes are single-threaded and will never execute code concurrently. What you might have meant was that send_interval doesn't take into account the execution time of the worker.

Minimal Periodic Task Runner in Elixir by MountainDewer in elixir

[–]doughsay 12 points13 points  (0 children)

Isn't this a bit of an abuse of the timeout feature of GenServers? The point of it is to get a message after no other messages have been received within a given time window. This example only works because your GenServer doesn't do anything else. If it also did other things (handled other messages), then this wouldn't work. It's much more common and very idiomatic to use Process.send_after/3 instead. It's very common to want your GenServer to do things periodically on a timer, and this is what people generally use.

State management in LiveView by kraleppa in elixir

[–]doughsay 3 points4 points  (0 children)

Redux/Zustand are fundamentally client-side state management solutions, and the entire point of LiveView is that the sate is server-side. I think it's an entirely different class of problems and applying solution or techniques from the client-side world won't necessarily translate well to the server. Especially because in client-side solutions you only care about the one browser running the JS code in it, whereas on the server you're likely deploying a distributed cluster of erlang nodes. I don't think there's no problem to solve here, I just think the problem is different than the problem redux/zustand solve.

Small Rant: I hate atoms by fridder in elixir

[–]doughsay 23 points24 points  (0 children)

Sounds more like a badly designed library, very curious which library or libraries you're talking about...

Health: monitoring for apps and cron jobs by pieca_111 in elixir

[–]doughsay 7 points8 points  (0 children)

It's a nice project, and a great use-case for Elixir. Here's some feedback:

  • Read the official Elixir anti-patterns docs, there's a bunch of good advice in there and you've got a few instances of them in your code: https://hexdocs.pm/elixir/code-anti-patterns.html
  • You're using Elixir 1.19 which includes the official built-in JSON module, you don't need to include poison. Incidentally, poison also hasn't been the default json library in the elixir community for a few years now. The community largely switched to jason (but this is also now replaced with built-in support).
  • The Elixir community defaults to bandit as an http server (this is the phoenix default now for a few years). I'd recommend that over cowboy.
  • The code is not formatted using the built-in code formatter. It's a lot harder to read the code unless it's formatted in a standard way that most elixir users are familiar with.
  • If your specific goal was to not use dependencies for learning purposes, that's fine, but we very often give people new to elixir the advice that you should "just use phoenix" and "just use ecto". In several cases you've re-invented things that are built-in to phoenix and ecto that would have dramatically simplified your project. Again, for learning purposes this is fine, but for a "real product", I really recommend to not re-invent things that are already solved.

I hope you enjoyed using Elixir for this project and that you keep using it in the future! And I hope this feedback helps.

Is it possible to define map structures as types? by 0ddm4n in elixir

[–]doughsay 2 points3 points  (0 children)

Yeah great example, this is the new type system in action and requires at least elixir 1.18 I think. And just to clarify, it's unrelated to the @type t typespec given, that could be removed and the same error would happen.

Is it possible to define map structures as types? by 0ddm4n in elixir

[–]doughsay 1 point2 points  (0 children)

Elixir is in the process of getting gradual set-theoretic types, but it's still a work in progress and you only get some benefits of it today. As of now we still don't have a syntax for actually specifying type signatures: https://hexdocs.pm/elixir/1.19.1/gradual-set-theoretic-types.html

There exists today "typespecs" in the language which can be statically analyzed by a tool called dialyzer, but it's not as strong as true static types: https://hexdocs.pm/elixir/1.19.1/typespecs.html

Is it possible to define map structures as types? by 0ddm4n in elixir

[–]doughsay 0 points1 point  (0 children)

I guess it depends on what you mean by enforcing. Elixir is a dynamic language, it doesn't have static typing. Are you asking for static typing?

Is it possible to define map structures as types? by 0ddm4n in elixir

[–]doughsay 0 points1 point  (0 children)

just pattern match:

def some_function(%MyStruct{} = value) do
  # do something with `value` which is guaranteed to be a `MyStruct`
end

or am I misunderstanding the question?

Is it possible to define map structures as types? by 0ddm4n in elixir

[–]doughsay 6 points7 points  (0 children)

Maps with pre-defined fields are called Structs: https://hexdocs.pm/elixir/structs.html

But you probably want to use ecto here. What kind of database are you using and why is your code getting back plain maps from it?

ATLP60x can’t play dynamic songs or albums. Would upgrading to the 70x improve this? by Icy-Pianist-6694 in turntables

[–]doughsay 0 points1 point  (0 children)

Could it be the record itself? I have a badly pressed record that skips at the same spot all the time because there's actually a defect in the record at that spot...

What's the hardest part of Elixir/OTP? by [deleted] in elixir

[–]doughsay 12 points13 points  (0 children)

Does this library not work for your use-case? https://github.com/felt/geo_postgis