Therefore:
- Separating data from code is inherently beneficial, even though it adds complexity to your code.
- High level languages, with easy-to-use data structures which can stand conveniently independent of your application code, are the easiest way to build this kind of separation.
- HERESY ALERT: The classic model of classes and objects (encapsulating data and code within an atomic unit) is inherently bad. END HERESY, SAFE TO CONTINUE READING.
For my Twitch channel bot, which supports full hot-reloading, the basic model is: a core event loop that dispatches to “this named function in the current version of this module”, allowing modules to be reloaded at will. Every function/method call is given a parameter which contains its most important state, stored in a plain data structure (eg a dictionary - not a custom class), and there’s room for globally shared state too. Every function is built to regularly return control to the main event loop.
There IS extra complexity to doing this. You have to think about your code and figure out how to divide it up so that it can return control to the main loop frequently (sometimes that’s trivially easy, sometimes not so much), and you have to plan your data structures and then maintain backward compatibility as you update the code. But the payoff is spectacular: full reloading capability at module granularity, with open files (especially sockets) being retained from one version of the code to another.