upvote
> Immediate mode GUIs like Dear Imgui or Clay allow for super-simple looking code in basic C

Layout computation is always awkward in immediate guis. You have to do an extra pass or throw away a frame.

reply
Clay's algorithm actually does many passes, that doesn't mean it invokes the UI function multiple times. You are allowed to retain state during computation.

Here's a cool explainer video:

https://www.youtube.com/watch?v=by9lQvpvMIc

reply
> I think it was the right call by the C++ people to explicitly list what objects are captured and how

Having recently worked a lot with Rust, which does this implicitly - I find the explicit notation entirely unnecessary. There's only one choice - are captures moved into closure or passed by reference? - and everything else is inferred. It does lead to some verbose cloning when there are many refcounting pointers at play, but other than that it works flawlessly; I've never been in a situation I couldn't do something I wanted to.

I'm confused by the point about RAII. Why are you saying that closures break it? Personally, I found that closures complement RAII very well - the closure owns its resources, and when it goes out of scope they're all cleaned up automatically. Or do you mean situations where resources outlive the closures? This is no different than any other object that needs a reference to something that lives longer.

reply