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.
views:
135answers:
7LISP, 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.
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.
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.
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.