3 ms·
I'm also curious, I think what it comes down to is that Clojure lets you change the code of a running application, rather than reload it.
by joshlemer 5y ago
I'm also curious, I think what it comes down to is that Clojure lets you change the code of a running application, rather than reload it.
- jimbob45 5y agoYou can do that with C# in Visual Studio though.
- Nihilartikel 5y agoThe greater Clojure hot-reload super power comes from embracing the idiomatic division of state and function though. Hot reload in C# will have probably have to re-instantiate classes or restart the app. In clj, if your application state is kept in a global atom a'la (defonce app-state (atom {})) Then redefining your functions won't touch your data. The only reason to do a full restart would be if you changed the data structure expected by the functions in a way that's not semantically backwards compatible. Big-whoop on a stateless webserver, maybe, but on the front end using ClojureScript for an SPA it is nothing short of magical and has ruined any other browser dev work flow for me.
- mikelevins 5y ago...and Common Lisp and Smalltalk take it a step further. You can go ahead and change the data structure in a way that's semantically incompatible. The runtime will notice that the definition has changed and either automatically reinitialize any existing instances to conform to the new definition, or, if it doesn't know how to do that, pose a UI asking you to tell it how. And when control reaches a function that expects the old kind of object and runs into an error, it'll enter a breakloop that you can use to modify the now-out-of-date function to handle the new definition properly. Once you've redefined the function you can then tell the runtime to resume and it will proceed as if the function you called had originally had the new definition.