Stream: ideas

Topic: Encode/Decode and reflection use-cases


view this post on Zulip Dan G Knutson (Jan 10 2026 at 23:38):

I was thinking about some game-dev cases where I originally thought that Roc would end up needing reflection, or where I / the platform would end up needing to use template-based source code generation. I think most or all of them can be handled using encode/decode.

  1. nicer hot reload
    Rust's new hot-patching solution, and the traditional dynamic linking that C devs do for games both run into a problem when editing a struct definition. If you add a field, you end up in undefined behavior territory. I was thinking of exposing some kind of type-level id or hash that would change in these cases. But you can make that an encode format! So you end up with the platform receives a reload event, and it calls world.encode(TypeLevelHash), and then if the 'encoded' type id is different, it can skip to reloading the scene (ie call init) instead of crashing or doing something undefined.

  2. exposing fields to an editor gui
    This is kind of more straightforward. You encode to some List(EditableField) type, almost like encoding to json, and then display that in the editor ui. Then you have some kind of try_edit(Entity, List(EditableField)) -> Try(Entity, EditError) sort of method for applying edits from the editor.

I'm fuzzier on it, but I think some of the ECS-like apis I was thinking of generating with templates could also be done this way.

Anyway, this is kind of stray thinking-out-loud. But it seemed interesting, and I'm curious if this kind of "encoding into a format that's not really a format" thing is intended or 'friendly' use of the interface.

view this post on Zulip Brendan Hansknecht (Jan 11 2026 at 00:04):

With inspect (which really is just a version of encode), we made something very similar to 2. It would make a little render of an arbitrary variable.

view this post on Zulip Dan G Knutson (Jan 11 2026 at 14:54):

I guess I'm wondering if a platform or library doing this kind of thing (outside of dbg/inspect) would be considered unsupported, even if it temporarily works.

view this post on Zulip Brendan Hansknecht (Jan 11 2026 at 19:19):

I think this should be fully supported by encode. I would have to double check the design to see if it is missing something, but it's a feature we want.


Last updated: Jun 16 2026 at 16:19 UTC