News for hackers. Stuff that matters.
Re:I Tried Gleam for Advent of Code, and I Get the Hype by miki123211 on Saturday December 13, 2025 @03:57PM (#46257967)
> Hi, I’m the creator of Gleam!

What's the state of Gleam's JSON parsing / serialization capabilities right now?

I find it to be a lovely little language, but having to essentially write every type three times (once for the type definition, once for the serializer, once for the deserializer) isn't something I'm looking forward to.

A functional language that can run both on the backend (Beam) and frontend (JS) lets one do a lot of cool stuff, like optimistic updates, server reconciliation, easy rollback on failure etc, but that requires making actions (and likely also states) easily serializable and deserializable.

Re:I Tried Gleam for Advent of Code, and I Get the Hype by lpil on Saturday December 13, 2025 @04:08PM (#46258070)
You can generate those conversions, most people do.

But also, you shouldn’t think of it as writing the same type twice! If you couple your external API and your internal data model you are greatly restricting your domain modelling cability. Even in languages where JSON serialisation works with reflection I would recommend having a distinct definition for the internal and external structure so you can have the optimal structure for each context, dodging the “lowest common decimator” problem.

Re:I Tried Gleam for Advent of Code, and I Get the Hype by miki123211 on Saturday December 13, 2025 @04:14PM (#46258143)
I understand your point, and I agree with it in most contexts! However, for the specific use case where one assumes that the client and server are running the exact same code (and the client auto-refreshes if this isn't the case), and where serialization is only used for synchronizing between the two, decoupling the state from it's representation on the wire doesn't really make sense.
Re:I Tried Gleam for Advent of Code, and I Get the Hype by lpil on Saturday December 13, 2025 @05:35PM (#46258878)
Totally. This is where I would generate them.
Re:I Tried Gleam for Advent of Code, and I Get the Hype by premek on Saturday December 13, 2025 @06:10PM (#46259135)
>You can generate those conversions, most people do.

Hi, what do people use to generate them, I found gserde (edit: and glerd-json)

Re:I Tried Gleam for Advent of Code, and I Get the Hype by okkdev on Saturday December 13, 2025 @08:18PM (#46259966)
The language server code action :)
Re:I Tried Gleam for Advent of Code, and I Get the Hype by lpil on Sunday December 14, 2025 @04:03AM (#46261783)
There’s several options, depending on what you want. The most commonly used option is the language server.
Re:I Tried Gleam for Advent of Code, and I Get the Hype by premek on Sunday December 14, 2025 @11:14AM (#46264102)
Oh nice, didn't know about it. (I have migrated from vim to neovim and half of it doesn't work for me yet)

I wonder why this is preferred over codegen (during build), possibly using some kind of annotations?

Re:I Tried Gleam for Advent of Code, and I Get the Hype by lpil on Sunday December 14, 2025 @12:48PM (#46265060)
We've not had any proposals for a design like that. We are open to proposals though! I wrote a blog post detailing the process here: https://lpil.uk/blog/how-to-add-metaprogramming-to-gleam/
Re:I Tried Gleam for Advent of Code, and I Get the Hype by lawn on Saturday December 13, 2025 @04:05PM (#46258051)
This is also what really annoyed me when I tried out Gleam.

I'm waiting for something similar to serde in Rust, where you simply tag your type and it'll generate type-safe serialization and deserialization for you.

Gleam has some feature to generate the code for you via the LSP, but it's just not good enough IMHO.

Re:I Tried Gleam for Advent of Code, and I Get the Hype by lpil on Saturday December 13, 2025 @04:10PM (#46258091)
Multiple of such tools exist and have done for years. Serde isn’t a Rust-core project, and similarly the Gleam alternatives are not Gleam-core.
Re:I Tried Gleam for Advent of Code, and I Get the Hype by lawn on Saturday December 13, 2025 @04:21PM (#46258187)
Rust has macros that make serde very convenient, which Gleam doesn't have.

Could you point to a solution that provides serde level of convenience?

Edit: The difference with generating code (like with Gleam) and having macros generate the code from a few tags is quite big. Small tweaks are immediately obvious in serde in Rust, but they drown in the noise in the complete serialization code like with the Gleam tools.

Re:I Tried Gleam for Advent of Code, and I Get the Hype by sshine on Saturday December 13, 2025 @07:30PM (#46259668)
> Rust has macros that make serde very convenient, which Gleam doesn't have.

To be fair, Rust's proc macros are only locally optimal:

While they're great to use, they're only okay to program.

Your proc-macro needs to live in another crate, and writing proc macros is difficult.

Compare this to dependently typed languages og Zig's comptime: It should be easier to make derive(Serialize, Deserialize) as compile-time features inside the host language.

When Gleam doesn't have Rust's derivation, it leaves for a future where this is solved even better.

Re:I Tried Gleam for Advent of Code, and I Get the Hype by lpil on Saturday December 13, 2025 @05:35PM (#46258871)
In Gleam code generators are most commonly used, similar to in C#, Go, or Elm.
Re:I Tried Gleam for Advent of Code, and I Get the Hype by lawn on Sunday December 14, 2025 @01:58AM (#46261289)
Yes, my point is that it's not a good experience.
Re:I Tried Gleam for Advent of Code, and I Get the Hype by lpil on Sunday December 14, 2025 @04:01AM (#46261772)
I would be very interested in hearing about your experience writing Gleam and the problems you have!

We regularly collect feedback and haven’t got problems reported here, so your feedback saying otherwise would be a useful data point.

Re:I Tried Gleam for Advent of Code, and I Get the Hype by lawn on Sunday December 14, 2025 @04:30AM (#46261890)
I might try to collect my thoughts somewhere when I get some time over.

Thank you for Gleam btw, I do really like the rest of the language.

Re:I Tried Gleam for Advent of Code, and I Get the Hype by worthless-trash on Sunday December 14, 2025 @01:56AM (#46261285)
Also. The lisp cam now generate serialisers and deserializers for some types iirc.