Is there any programming language that can combine editing and compiling / running?

When I code, I always write small chunks of unit and compile it often. This helps me make sure everything is working correctly, but it takes a very long time. Is there any programming language that can help us do coding and work side by side at the same time? I mean, as soon as a key press results in valid code, the edit effect is included in the runtime program.

+2


a source to share


7 replies


What you are looking for is sometimes called a brisk system, an incremental system, or a self-sustaining system (S³).

This is not really a property of a programming language, it is a matter of a development environment. The only thing that has to do with the programming language is that some programming language communities are strongly opposed to the very idea of ​​animation, and therefore these communities usually do not produce living tools, while other communities cannot imagine life without a living system. so they tend to produce them.

For example, almost all Smalltalk environments and many Lisp environments are live environments, and I don't know of any live C or C ++ environments. There used to be a lively Java environment called IBM Visual Age for Java (which was actually written in Smalltalk by IBM Smalltalk and based on IBM Visual for Smalltalk so there were no surprises), but when it was rewritten in Java as Visual Age for Java Micro Edition (which you probably know better by its current name, Eclipse), it has lost its vivacity.

You are asking about "coding and running at the same time". Well, in a live system they are not even "side by side", they are actually the same thing: there is no difference between coding and launching, there is no difference between IDE and application, there is no difference between compilation time and runtime.

How often do you develop software in Smalltalk, you just write what you want and run it:

aCalculator ← Calculator new.
aCalculator compute: '1 + 1'.

      

(BTW: "Run" just means writing this little piece of code into any text area anywhere on the screen, highlight it and hit "Run.")

[Note: left arrow - destination (think =

), up arrow - return

. The original Smalltalk systems had them on the keyboard, modern systems usually use :=

and ^

. In addition, the space represents the sending of the message ("dot" in Java), and the period ends the sentence ( ;

) in most languages. Method arguments are passed inline in the message itself after the colons, not in parentheses.]

Of course this doesn't work because the class Calculator

doesn't exist yet. So the debugger pops up (did I mention the difference between launching and debugging?), And one of the options it offers you is to create this class. You don't restart the program, it just keeps running. Now you are getting a new error because the method compute:

does not exist. Again, the debugger prompts you to create this method for you, and you can directly enter the code right there: (Did I mention the difference between a debugger and an editor?)

compute: aString
    ↑ 2.

      



The system has already filled in the method name for you and chose a (somewhat) sensible name for the method parameter. You only need to enter the second line.

(By the way: if this workflow is familiar to you, it should. Kent Beck founded the object model and execution model of his two test frameworks (SUnit and JUnit), as well as the Test-Driven Development and Red-Green-Refactor practices on this workflow.)

Please note that we have never stopped or restarted the running program. We have always edited the live system source code from the system while the system is running. In fact, you cannot actually stop a Smalltalk program or Smalltalk system! Even if you shutdown the Smalltalk system, what it actually does is to serialize the entire system state (every class, every object, every variable, every thread, every window, even the position of the mouse pointer) to disk, and when you start it again, you are exactly where you left off. The system never stopped, it was just frozen. (If you're familiar with VMWare, Parallels, VirtualBox, or something like that, he likes to take a snapshot of the virtual machine or think about hibernating or suspending your computer.)

In fact, if you download the Squeak version today, there are probably objects out there that have literally been working for 30 years. (This is another difference between Smalltalk and other systems. Smalltalkers believe that, like fine wines, objects get better with age. This is in stark contrast to, for example, PHP or Ruby on Rails, where objects can be thrown out heavily after each web request.)

One of the most famous examples of this lively editing is the key "Apple Demo" when Steve Jobs, Jeff Raskin, and other members of the Lisa team visited Xerox PARC in 1979 to get a demo of the Smalltalk system:

One of the best parts of this demo was when Steve Jobs said he didn't like the stylish scrolling blt

we were using and asked if it was cool to do it in a fluid, continuous style. Less than a minute later Dan [Ingalls] found methods that made (relatively large) changes and the scrolling was now continuous! This shocked the visitors, especially the programmers among them, as they had never seen a really powerful incremental system before. Early History of Smalltalk by Alan Kay, HOPL-II, & copy; 1993 ACM

Oh, and yes, you heard that right: Dan Ingalls rewrote the video driver in the live system, from within the live system, without rebooting the system or even suspending the application. In less than 60 seconds. (Didn't I mention the difference between a programming language and an operating system?)

One of the best explanations for the properties of liveliness can be found in the video Self; Movie ("I" is a Smalltalk derivative). Also, take a look at the Lively Kernel by Dan Ingalls (one of the original Smalltalk designers), which is basically a Smalltalk port of JavaScript ideas running inside a web page.

As I wrote above, this is really a feature of the environment, not the language. So, although I used Smalltalk here as an example, you could implement a live system for any language. I already mentioned Lisp as a language for which there are many lively environments, and I gave an example for JavaScript. APL and Forth systems tend to be alive. Factor is a good example of a living system. The most extreme example would be the real-time VxWorks operating system, which contains a semi-live system for C (!), Which was used to diagnose and fix a priority inversion problem leading to false system failures on a Sojourner router on another frigin Planeta!

+3


a source


Once a key press results in valid code, is the editing effect included in the executable?

As noted above, many languages ​​offer an interactive read / edit / eval / print loop, but you are asking for something else. The Symbolics Lisp machines of the 1980s offered functionality in much the same way you describe; you need to press one key to update the running system. You can even replace the function without breaking the old activations of previous versions in the call stack.



The 1970s and 1980s were a golden age for interactive development environments, and the field has languished ever since. Nowadays people think of Visual Studio as a highly integrated programming environment - and it is, but less dynamic.

I think the closest you could come today to replicate such a dynamic experience is Squeak Smalltalk , which is a very sophisticated Smalltalk-80 IDE built on Xerox PARC (and by the same people).

+4


a source


LISP, Schema, 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.

Hell, even shell counting, really.

Quoting from Wikipedia: command line interpreter :

Although most users think of the shell as an interactive command interpreter, it is indeed a programming language in which each statement executes a command. Since it has to satisfy both the interactive and programmatic aspects of command execution, it is a strange language, shaped like a story, by design.

- Brian Kernigan and Rob Pike


For a video demo, see Conway Game of Life at APL .

+3


a source


I don't think this is necessarily a language issue as it is an IDE issue etc. Even compiled languages ​​like C have translators for them.

Perhaps you can find a translator for what you are programming if you think it will help you.

+1


a source


Erlang allows you to modify a running program, essentially the ability to update methods on the fly when the program never stops running.

+1


a source


Well, I'm working on what needs to be done in a free time hobby project. It uses a statically typed compiled language called Eiffel.

The difference with traditional compilers is that the compiler acts as a server, not a command line program. It stores all the data parsed in memory and actually does incremental compilation on it. With an incremental linker all in memory, the idea is to have a compile / link / run cycle of less than 2 seconds.

But yes, there is still a problem that you can only solve in languages ​​like Lisp or Smalltalk. That the code always starts with Adam & Eve and should jump to a specific situation in your program.

But currently, this seems to be the best compromise if you want a really fast executable language. Revitalization requires a lot of performance to be wasted because the existing object structures have to be preserved in some way, theoretically possible, but the implementation is very complex.

0


a source


Hmm, do you really want something like that?

Suppose you have a system like this configured for your C environment. So your editor is set up so that every keystroke it checks to see if it results in valid code ... how? If your editor does not use redundant logic like a compiler / interpreter when parsing your code, you will have to call the compiler. (Let's ignore the overhead of saving the file to disk, and imagine that your compiler can directly read the contents of your editor buffer.) So every time you press a key, it compiles the code. You will probably get errors 99% of the time, simply because you did not fill out the variable name or keyword. How does your system know if the error is related to this or is due to a "real" error?

Also, how would you make changes to the program while it is running? Suppose your program is at the point of five frames on the stack, and you change the value of the variable that is passed to the first function. There is no way to magically propagate changes without re-running this first function. But if the change does not apply, was it really included in the program? Of course, the debugger will allow you to modify existing variables in the executable program, but you cannot do things like create new variables or call functions or control structures, anything you can do according to your schema.

Most built-in languages ​​have a Read-Evaluate-Print Loop (REPL) where you can define functions that are then stored in the interpreter environment, and you can call those functions by name and even override functions such that previously defined functions that call them , then new versions will be executed. But even so, your program is not executed anytime you have a hint, and thus it can give it something new to interpret.

-2


a source







All Articles