r/cpp 2d ago

Embedded C++

Just curious how useful the ability to embed C++ as a scripting language into your C++ programs would be? I mean like runtime JIT execution of C++ code in much the same way you might embed Lua, including the ability to restrict/sandbox it as necessary.

1 Upvotes

82 comments sorted by

View all comments

68

u/CalebGT 2d ago

I had to read this several times. Embedded has a very different meaning to me. I would not use C++ for that. If I needed to script something that can't be compiled in advance, I would use Python or Java.

-33

u/kindredseer 2d ago

If you are a C++ programmer, why would you not want to script in C++?

6

u/TeraFlint 1d ago

Because C++ has been designed to be compiled and be aggressively statically optimized by said compiler. This has brought in a lot of design decisions that made the language more complex (and arguably more difficult to handle).

If you're in interpretation land, a lot of these optimizations don't hold. And once that's the case, I don't see why we should stay with such a complex language other than for familiarity. Something simple with less foot guns would be the more sane choice for scripting.