Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.





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.

Totally. This is where I would generate them.

>You can generate those conversions, most people do.

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


There’s several options, depending on what you want. The most commonly used option is the language server.

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?


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/

The language server code action :)



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: