Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I would like to build a "live coding framework".

I should explain what is meant by "live coding framework". I'll do so by comparing live coding to traditional coding.

Generally put, in traditional programming you write code, sometimes compile it, then launch an executable or open a script in some sort of interpreter. If you want to modify your application you must repeat this process. A live coding framework enables code to be updated while the application is running and reloaded on demand. Perhaps this reloading happens each time a file containing code is changed or by some other action. Changes in the code are then reflected in the application as it is running. There is no need to close the program, to recompile and relaunch it.

In this case, the application is a windowed app that has an update/draw loop, is most likely using OpenGL for graphics, an audio library for sound processing ( SuperCollider? ) and ideally a networking lib.

Of course I have preferred languages, though I'm not certain that any of them would be well suited for this kind of architecture. Ideally I would use Python, Lua, Ruby or another higher level language. However, a friend recently suggested Clojure as a possibility, so I am considering it as well.

I would like to know not only what languages would be suitable for this kind of framework but, generally, what language features would make a framework such as this possible.

share|improve this question
1  
What you are describing sounds a lot like how a smalltalk environment works. Check out Squeak, a free ST implementation: squeak.org (I'm posting this as a comment instead of an answer as I'm not sure if you want something pre-existing like this, or want to build something like it) –  Tristan Havelick Oct 25 '11 at 20:36
    
Squeak looks pretty interesting. Even if I don't end up using it I'm sure I'll find it educational. Thanks! –  jeremynealbrown Oct 25 '11 at 20:54
1  
Don't ever make a typing mistake in your "live coding framework". :-) –  Gilbert Le Blanc Oct 26 '11 at 14:52
1  
Erlang/OTP runtimes also work this way, they can load new modules on the fly. –  Patrick Hughes Jan 18 '12 at 4:29

5 Answers 5

You mean like a REPL? Any language in the Lisp family makes designing one fairly trivial and most come with one already. Haskell also comes with one. It's the preferred coding method of the author of "Learn You a Haskell".

share|improve this answer
    
Possibly like the REPL. It sounds like something I should become more familiar with. The key element here is that I'm looking for something to write complete UI applications with. Thanks for the Haskell suggestion. I have yet to look at that language in depth. –  jeremynealbrown Oct 25 '11 at 20:19
    
pretty much all languages with a scripting heritage have some sort of REPL, iaw TCL, PERL, Python, Ruby etc. –  jk. Jan 17 '12 at 14:07
    
You can write a REPL for any language, even C. c-repl –  Raynos Jan 18 '12 at 0:45
    
The question is how much effort you want to put into developing such an environment. –  World Engineer Jan 18 '12 at 4:49

The Erlang VM has facilities for hot swapping of code (that is, loading new code without stopping the program), which I gather is what you're talking about.

share|improve this answer

LISP does this. So does SQL, though there's not much UI there. (SQL came to mind because on some of the old database systems like Revelation or dBase, you COULD update forms at runtime on the server and have 'em show up on the clients.)

The language feature that makes this work is late binding. If client code has to grab the implementation of the code it calls at runtime, you have the chance to get in ahead of it and change what the implementation is.

share|improve this answer

There's a project called fluxus which uses the Scheme programming language to implement live coding.

There's an implementation for Mac OS X called impromptu.

I would recommend using Common Lisp or Scheme since the implementations typically allow for compiling on a command-line interface. Other languages that are implemented like this are Forth and Smalltalk. There are hacks that you can use in Python and other language implementations where the code is compiled separately and reloaded quickly. I know this has been done for C and Java.

share|improve this answer
1  
+1 for familiar names of two great projects –  Nek Aug 23 '12 at 12:39

I've been working on some architecture for live coding.

The basic premise is that you write a small Core library which you can attach modules to.

The modules themself need to know how to attach and detach themself from the core and how to initialize and destroy themself.

If they do, then modules can be easily and safely removed or reloaded.

To help with easy detachment/destroyment I've used a central mediator for modules to talk to each other. This means modules don't hold hard references to other objects but hold a reference to a single mediator.

Note this mediator never gets reloaded or removed from the codebase because every existing module has a reference to it. The mediator and the core is a very small and stable library that never gets updated because something needs to be consistent.

So basically what allows live coding is

  • a static mediator that never changes that every module can talk to. This is the entry point that always exists which all new modules can consistantly talk to.
  • every module knows how to "reload" or "remove" itself from the run-time application
  • some lightweight infrastructure that watches the file system and reloads modules when files changes

I have an implementation of this for node.js called nCore

The same concept could be implemented in any interpreted language. The concept might need reworking for compiled languages.

There is no reason the same concept cannot be done in C with each module being a pointer to a struct, and when a module gets reloaded, the struct is overwritten in memory whilst the program is running.

As long as the pointer to the mediator stays absolutely constant any struct added to the running application should know how to talk to it. You can add as many modules as you want at run-time, just add a new struct to memory and pass the memory pointer directly to the core.

Do note that this does not garantuee anything about availability. The naive way to hot reload say a HTTP server is to destroy and reboot it with the new code. You would need some heavier loadbalanced infrastructure to garantuee availability.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.