views:

135

answers:

7

When I code, I always write little pieces of unit, and compile it often. This helps me to make sure that everything run correctly, but it's very time consumed. is there any programming language that can support us to do coding and running at the same time side by side ? i mean as soon as a key press leads to valid code, the effect of the edit is incorporated into the executing program.

+3  A: 

LISP, Scheme, Haskell, Perl, Python, Ruby, Maple, Mathematica, MATLAB, etc. Most interpreted languages can do this. Your code is interpreted and run as soon as you finish typing it.

Heck, even command shell counts, really.

Quote from Wikipedia: Command line interpreter:

Although most users think of the shell as an interactive command interpreter, it is really a programming language in which each statement runs a command. Because it must satisfy both the interactive and programming aspects of command execution, it is a strange language, shaped as much by history as by design.

– Brian Kernighan & Rob Pike


For a video demo, watch Conway's Game of Life in APL.

polygenelubricants
+1  A: 

I don't think that it's necessarily a matter of language as it is a matter of IDE and such. Even compiled languages like C have interpreters for them.

You can probably find an interpreter for whatever you are programming in if you think it'll help you.

Xzhsh
A: 

Hmm, do you really want something like this?!

Let's imagine you have such a system set up for your C language environment. So, your editor is configured so that at every keypress it checks if it "leads to valid code"... how? Unless your editor redundantly incorporates all the same logic as the compiler/interpreter in parsing the code, you'll have to invoke the compiler. (Let's ignore the overhead of saving the file to disk and imagine your compiler can directly read the contents of your editor's buffer.) So at every keypress it compiles the code. You're probably going to get errors 99% of the time, just because you've haven't completed typing the name of a variable or keyword. How will your system know whether the error is due to that or due to a "real" error?

Also, how would you incorporate edits into a program while it is executing? Suppose your program is at a point five stack frames deep and you change the value of a variable that gets passed to the first function. There's no way to magically propagate the changes without starting execution at that first function again. But if the change isn't propagated, was it really incorporated into the program? Of course a debugger will let you modify existing variables in an executing program, but you can't do things like create new variables or function calls or control structures, all things which you might do under your scheme.

Most intepreted languages have a Read-Evaluate-Print Loop (REPL) where you can define functions which are then stored in the interpreter's environment, and you can call those functions by name, and even redefine the functions such that previously defined functions that call them will then execute the new versions. But even in this case, your program is not executing any time you have a prompt and are thus able to give it something new to interpret.

Paul Richter
The new visual studio actually does a compile/parsecheck in the background with every keystroke you type, letting you show compile errors before you compile ;^)
Toad
Thanks, reinier, for the information. I figure there probably was something out there that actually did all these things I said were impossible or impractical; I was vaguely aware of Erlang as you answered below.So will the next version of MSVC show compile errors before typing anything at all?
Paul Richter
@paul richter: I'm not suggesting Visual studio includes a REPL for c# or c++ (although for f# it is included). I'm just suggesting that compiling at every keystroke is something which does happen nowadays. For showing compile errors before we type them we'll have to wait for the quantum computers ;^)
Toad
+1  A: 

Erlang allows you to modify a running a program, essentially being able to update methods on the fly while the program is never stopped running.

Toad
+4  A: 
Norman Ramsey
+3  A: 
Jörg W Mittag
As always, your answer is interesting, thorough, and leaves a few doors open if we want to learn more. Thanks!
Corbin March
A: 

Well i'm working on somethink like this on a hobby spare time project. It's using a static typed compiled language named Eiffel.

The difference to traditional compilers is that the compiler works as a server and not a command line program. It keeps all data parsed in memory and really does an incremental compilation on them. Together with an all in memory incremental linker the idea is to have a compile/link/run cycle of less then 2 seconds.

But yes there is still a problem you can only solve with image based languages like Lisp or Smalltalk. That the code always starts with Adam&Eve and has to make its way up to a defined situation in your program.

But currently this seems to be the best compromise if you need a really fast executable language. The livelyness requires that a lot of performance is wasted cause existing object structures must be preserved in some way, Theoretically it is possible but the implementation is very complex.

Lothar