In compiled languages like Rust and C++
Implementing hot reloading in GUI development is challenging
Languages like Dart (Flutter) has hot reloading cuz it can compile JIT and AOT
Do you think Cling can help implement hot reloading easily in C++ for rapid UI development ?
Welcome to the ROOT Forum!
And sorry, but I have no idea of what you’re talking about. Can you give a concrete example?
1 Like
I have a GUI interface with ROOT-Cling-C++ and there is a window implementing a live-interpreter.
So from the terminal, I can modify the GUI in real time. Not sure if that’s what you want.
See ROOT: TGCommandPlugin Class Reference
1 Like
When you building a GUI using compiled languages like Rust, C or C++, you need to recompile the whole program every time you make some changes to the code.
This is cumbersome cuz you lose the GUI state and sometimes you need to navigate a lot to reach the part of the GUI you were working on.
In JS or Flutter (Dart) development you have hot reloading, the GUI preserves its state, only applying the changes you made to the code without recompiling the whole program.
i read that C++ has something called live++ which does the same thing but its closed source.
Discussions about hot reloading always state that compiled languages lack this feature cuz there is no “binary patching” and due to its progressive and AOT compiler nature.
I have no knowledge about this “binary patching”, but i was wondering if cling can do that thing, making hot reloading in C++ GUI development possible ?
@ferhue What i am referring to is that you edit the code in your IDE, the JIT applies those changes to the GUI without compiling the whole program. I think that’s close to what you mentioned …
Not sure, I guess it depends on what type of classes you are using for the GUI and how it interfaces with the rest of the program. I guess the best thing is to try it out. Either in cling or in clang-repl.
1 Like
Not really related to ROOT, but if you use an immediate-mode GUI library you can implement a basic form of hot reloading, by:
- splitting your GUI code to a dynamic library which you dynamically load (with
dlopen
or equivalent on other platforms)
- monitor the dynamic library file for changes
- reload the library when the file changes.
This doesn’t require an interpreter and, as long as your library is reasonably written, you get your changes while the app is still running. The hardest part of this is organizing your data so that you don’t rely on per-library global state which would have to be reinitialized upon reloading. A pretty simple solution is just having your entire UI state allocated from outside the hot-reloaded library and passing it in to the library functions (which works well with immediate-mode GUI paradigms).
Else, you could theoretically write a hot reloading system on top of cling or clang-repl, but I’m not sure it would make things much easier, if at all. It is certainly a fair bit of work on your side either way.
1 Like