by brodul · 6y ago · 0 comments
There are some gotchas with hot swapping, but it's designed and used in production for many years [2].
If somebody knows other languages/systems that do let me know.
1. https://elixir-lang.org/ 2. https://stackoverflow.com/questions/37368376/how-does-erlang...
I've used this technique in multiple games written in Lua, as well as a GUI app written with wxLua, and I can't imagine programming a long-running program in Lua again without it.
There are many caveats like stale module local state but they can be circumvented by designing the program from the start to put such state into a separate module which gets preserved. You do also have to modify your program's code to accommodate hot swapping in some cases but I would say the effort is repaid many times over in time saved not having to restart the program and go all the way back to part you're testing again every time you make a change.
I really wish it were easier to do in popular languages like Python but because of the way it interacts with imports I feel like your only chance to get it right is in the early stages of language design. One time I was wanting to program games in Typescript to take advantage of gradual typing but couldn't figure out an equivalent way to do hot reloading like in Lua, so I went with Lua instead. I feel like if more people knew how much benefit it brings from using a language that supports it we might see more mainstream support in new dynamic languages.
Clojure can do this via namespace live reload. ClojureScript is already doing this inside figwheel [1] environment. CommonLisp had this since dawn of time. Kawa [2] can do it, but because it aggressively optimize the code, you need to be careful. Racket can do it as well [3].
[1] https://github.com/bhauman/lein-figwheel
[2] https://www.gnu.org/software/kawa/
[3] https://github.com/tonyg/racket-reloadable/tree/master#readm...
EDIT: added Kawa and Racket.
Anyway it’s a very well studied and covered topic in the Java ecosystem as I understand it...
http://blog.ruwan.org/2012/12/dynamic-hot-swap-environment-i...
def print_name(d):
print(d['name'])
d = {'name' : 'hello'}
while True:
print_name(d)
Now you hot hot-swap it while the while-loop is running: def print_name(d):
print('hello', d['first_name'])
d = {'first_name' : 'there'}
while True:
print_name(d)
Erlang can do this. No other language that I'm aware of can.there are also lesser known languages such as pike. although pike doesn't do hotswapping of actual objects but only allows the hotswapping of the compiled classes used to instantiate new objects. this works well enough on webservers where new objects are created for every request, and only live as long as the request is processed.
there is a platform called open-steam that emulates hotswapping by using proxy objects. when i reference an object, i actually get a proxy, that then references the real object. when i update the code, then the proxy gets updated to the new real object, and for me it looks like the object i am referencing has been hotswapped.