Reputation: 6585
I am wondering, are there any languages allows you to add/delete/update any class on the fly without reloading whole application? (Provided that I can accept some inconveniences like making sure that there is no methods running at the moment + some extra effort to 'migrate' class data members).
Web applications where you replace 1 file and it is used on the next client request is not what I need (like Perl, PHP). Application must be continuously running, and it have some internal state.
Other requirements are
About the answers already made:
Upvotes: 15
Views: 3059
Reputation: 657038
The Dart VM has great hot code reload support which greatly improves the Flutter development experience.
https://github.com/dart-lang/sdk/wiki/Hot-reload
Upvotes: 2
Reputation: 1128
Objective-C allows you to hot swap code, and there is a plugin which allows that. I answered similar question about Objective-C here
Upvotes: 0
Reputation: 1063
you should use php for this, i too have a linux server, it is very good with permission to change files like i have this php code to open a text box with an editable on site file,
<?php
$fn = "test.txt"; //the path to any file
if (isset($_POST['content']))
{
$content = stripslashes($_POST['content']);
$fp = fopen($fn,"w") or die ("Error opening file in write mode!");
fputs($fp,$content);
fclose($fp) or die ("Error closing file!");
}
?>
<h4>You are editing <?php echo $fn ?> </h4>
<form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post">
<textarea rows="25" cols="40" name="content"><?php readfile($fn); ?></textarea>
<br/>
<input type="submit" value="Save">
</form>
Upvotes: 0
Reputation: 9973
The following are generally considered dynamic languages:
Some of these languages are supported in the .NET Framework by the Microsoft Dynamic Language Runtime.
Upvotes: 5
Reputation: 15907
We do this with a Seaside smalltalk webapplication running on the free version of Gemstone. Gemstone has been doing this for the past 20 years or so, so they have everything you need. Some of the high-availability features are not free.
Open source smalltalks don't have the extensive class version/migration gemstone has. The simple 'load a new version and migrate all instances' works with all smalltalks.
Upvotes: 3
Reputation: 58521
Depending on the specifics of your project - Javascript might be the answer via Node.js (nodejs.com) which allows you to program an event based server using javascript that is interpreted by the V8 engine.
This approach can be ver efficient compared to traditional web-servers in circumstances where there are many connections at one time, and especially if there is a lot of idling around for the server. This is due to the event based nature of Javascript where the cost of idling is very low.
There are several methods for hot-swapping code using node.js - this should get you started: Node.Js in Erlang style? and https://github.com/kriszyp/nodules
Upvotes: 1
Reputation: 4866
You could look through the list at http://en.wikipedia.org/wiki/List_of_programming_languages_by_category#Reflective_languages. One that I don't see mentioned here yet is Lua, which has a reputation as being fast compared to other dynamic languages.
Another strategy might be to look at the academic research. A possible starting point is http://scholar.google.com/scholar?q=ksplice, which is about patching a running linux kernel.
I'm not sure what degree of automation you're looking for. Obviously the general case of seamlessly replacing a running instance of program A with A' is difficult, even with some guarantees on what is allowed to change in A'.
Depending on how the pieces of the program that need to be updated can be grouped and isolated, you could put them in a shared library, and (re-)load the shared library at run time (using e.g. the dlopen family of functions if you're on unix).
Upvotes: 0
Reputation: 14406
I have did some research on zero downtime service migration recently. And my solution is not a language-relative one. Here is the idea, we can dump the state of current service, create another process, transfer the connection state description to the new process, finally terminate the old process. As shown in following diagram:
With a well defined abstract service description format and migration protocol, you can migrate any kind of services from one process to another, which means, you could write a server in C++, and migrate the service to the new process written in Python without any disconnection. Of curse, you can migrate your service from the old version to the new version. Adding/Deleting/Updating classes won't be a problem. For more detail, you can reference to my article
Zero-downtime service migration
The difficulty of this kind of technique is that you have to dump the all state of the running service and load them on another process. For most libraries out there you could find, it is hard to get internal state of those classes, which means you may have to do some hack on them, or write your own library. It would be a nightmare to transfer service state for complex services, but for simple services, that's not a big deal.
Upvotes: 3
Reputation: 210352
Take a look at Scheme. You can do object-oriented programming in Scheme using very simple extensions, such as the Berkeley extensions. Just extend the code to allow for replacing methods (should be very easy) and you can hot-swap them however you want -- the syntax would still stay simple because, well... it's Scheme. :)
Right now, the code for the classlooks something like:
(define-class (person name)
(method (greet) (print `Hello!))
...)
where person
is a lambda. It should be pretty easy to change the define-class
macro to make person
a list, for example, so that you can add to or remove from it dynamically.
Upvotes: 2
Reputation: 118470
Python can do this. Note the following:
multiprocessing
module.Upvotes: 3
Reputation: 94794
Objective-C might fit the bill. You can use the functions documented here to add new classes and swap method implementations at runtime, and you can load new NSBundles with additional classes or categories on existing classes if additional implementations are required. GNUStep, while not implementing all of the recent Apple additions to the language, does claim to implement these features (see [1] and [2]).
Upvotes: 5
Reputation: 9714
Smalltalk can do it naturally, Common Lisp (CLOS) with a couple of tricks.
Upvotes: 0
Reputation: 61369
Erlang was designed to support hot code swapping as one of its high availability features.
Upvotes: 17
Reputation:
Java can do this with its debugging interface
http://download.oracle.com/javase/6/docs/platform/jvmti/jvmti.html#RedefineClasses
http://download.oracle.com/javase/6/docs/platform/jvmti/jvmti.html#RetransformClasses
or slightly older:
http://download.oracle.com/javase/1.4.2/docs/guide/jpda/enhancements.html#hotswap
Upvotes: 1
Reputation: 35613
What type of application are you trying to write? On what platform?
The question of GUI vs. Server may rule things out as will linux vs. windows.
The following languages are dynamic:
Modern JavaScript is currently in an arms race to be as fast as possible, so should be pretty quick on any platform.
Upvotes: 3