哪些编程语言功能非常适合开发实时编码框架?

发布于 2024-12-11 20:51:41 字数 521 浏览 0 评论 0原文

我想建立一个“实时编码框架”。

我应该解释一下“实时编码框架”的含义。我将通过比较实时编码与传统编码来做到这一点。

一般来说,在传统编程中,您编写代码,有时编译它,然后启动可执行文件或在某种解释器中打开脚本。如果您想修改您的申请,则必须重复此过程。实时编码框架允许在应用程序运行时更新代码并按需重新加载。也许每次包含代码的文件发生更改或通过其他操作时都会发生这种重新加载。代码中的更改会在应用程序运行时反映出来。无需关闭程序并重新编译并重新启动它。

在本例中,应用程序是一个窗口应用程序,具有更新/绘制循环,很可能使用 OpenGL 进行图形处理、用于声音处理的音频库(SuperCollider?)以及理想的网络库。

当然,我有更喜欢的语言,尽管我不确定其中任何一种语言都非常适合这种架构。理想情况下,我会使用 Python、Lua、Ruby 或其他高级语言。然而,一位朋友最近建议使用 Clojure,所以我也在考虑它。

我不仅想知道哪些语言适合这种框架,而且一般来说,哪些语言功能可以使这样的框架成为可能

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 and 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

清风无影 2024-12-18 20:51:41

我已经在 Lua 中实现了实时编码功能,作为 ZeroBrane Studio IDE 的一部分。它的工作方式与您所描述的完全一样,在代码发生更改时重新加载应用程序。我正在研究可能的改进,以在运行时修改值,以避免应用程序完全重新加载。它是一个纯粹基于 Lua 的解决方案,不需要对 VM 进行任何修改。

您可以在此处查看当前实现的实时编码演示:http://notebook.kulchenko.com/zerobrane/live-coding-in-lua-bret-victor-style

就使用/所需的语言功能而言,我依赖于:

  1. 中断/恢复正在运行的应用程序的能力(这基于 debug.hook 和 error() 调用)、
  2. 远程与(未修改的)应用程序交互的能力(这基于 debug.hook、与 select() 支持的 TCP 交互来检测是否从主机发送新请求,以及在协程上在主应用程序和实时编码模块之间进行切换,以及
  3. 能力将新代码注入到应用程序中(这机制也在使用协同例程,但我确信还有其他选择)。还可以仅注入修改后的片段,但它需要处于函数级别,并且如果该函数是某个其他函数的本地函数,则您也需要包含该函数,依此类推。

I have implemented a live coding feature in Lua as part of the ZeroBrane Studio IDE. It works exactly as you described by reloading the application when a change in the code is made. I'm working on possible improvements to modify values at run-time to avoid full reload of the application. It's a pure Lua-based solution and doesn't require any modifications to the VM.

You can see the demo of the live coding as currently implemented here: http://notebook.kulchenko.com/zerobrane/live-coding-in-lua-bret-victor-style.

In terms of language features used/required, I rely on:

  1. the ability to interrupt/resume a running application (this is based on debug.hook and error() calls),
  2. the ability to interact with the (unmodified) application remotely (this is done based on debug.hook, TCP interactions with select() support to detect if a new request is being sent from the host machine, as well and on coroutines to switch between the main application and the live coding module), and
  3. the ability to inject new code into the application (this mechanism is also using co-routines, but I'm sure there are alternatives). There is also a possibility to inject just a modified fragment, but it need to be at the level of a function, and if this function is a local to some other function, you need to include that too and so on.
画中仙 2024-12-18 20:51:41

Clojure 几乎拥有您作为实时编码语言可能想要的一切。主要亮点:

  • 交互式 REPL - 这样您就可以直接与正在运行的程序进行交互。即使当我进行“传统编程”时,我也倾向于交互式地编写代码,然后将我喜欢的部分复制到源文件中。 Clojure 就是为了这种方式而设计的 - 程序中的几乎所有内容都可以在运行时检查、修改和替换。
  • 强大的并发支持 - 您可以使用 (future (some-function)) 等代码轻松启动并发后台任务。更重要的是,Clojure 的 STM 和对高性能不可变数据结构的强调将处理更微妙的并发方面(例如,如果我在渲染过程中更新实时数据结构会发生什么??)
  • 库可用性 - 它是一种 JVM 语言,因此您可以从 Java 生态系统中获取所需的所有音频、视频、IO 或计算工具。很容易将它们包装在 Clojure 的一两行中,以便您获得所需函数的简洁界面
  • - 因为 Clojure 是一个 同像语言 您可以利用 Lisp 功能来编写扩展该语言的强大宏。您可以有效地构建要在实时环境中使用的确切语法,并让编译器完成在幕后创建完整代码的所有艰苦工作。
  • 动态类型 - 其好处可以从两方面论证,但当尝试快速而简洁地编写代码时,这无疑是一个巨大的好处。
  • 活跃的社区,有很多很酷的项目 - 您可能会在 Clojure 社区中发现很多人对类似的实时编码技术感兴趣。

您可能会发现一些有趣的链接:

Clojure has pretty much everything you are likely to want as a live coding language. Main highlights:

  • Interactive REPL - so you can interact directly with your running program. Even when I'm doing "traditional programming" I tend to write code interactively and copy the bits I like into a source file later. Clojure is just designed to work this way - pretty much everything in your program is inspectable, modifiable and replaceable at runtime.
  • Great concurrency support - you can kick off concurrent background tasks trivially with code like (future (some-function)). More importantly, Clojure's STM and emphasis on high performance immutable data structures will take care of the more subtle concurrency aspects (e.g. what happens if I update a live data structure while it is in the middle of being rendered??)
  • Library availability - it's a JVM language so you can pull in all the audio, visual, IO or computational tools you require from the Java ecosystem. It's easy to wrap these in a line or two of Clojure so that you get a concise interface to the functions that you need
  • Macros - as Clojure is a homoiconic language you can take advantage of the Lisp ability to write powerful macros that extend the language. You can effectively build the exact syntax that you want to use in the live environment, and let the compiler do all the hard work of creating the complete code behind the scenes.
  • Dynamic typing - the benefits of this can be argued both ways, but it's certainly a huge benefit when trying to write code quickly and concisely.
  • Active community with a lot of cool projects - you're likely to find a lot of people interested in similar live coding techniques in the Clojure community.

A couple of links you might find interesting:

梦幻的味道 2024-12-18 20:51:41

要实现这项工作,唯一需要的是一种动态绑定形式,例如,Erlang 中的消息传递或许多其他语言中的eval

如果您有动态绑定,那么您可以更改消息的目标而不影响消息,或者更改消息而不影响目标 - 前提是在您尝试向目标发送消息时定义了目标 ,并为您发送消息的目标定义消息,您发送消息时。

更改目标时,您所要做的就是向以前的版本提供消息,直到新版本就位,然后进行小型锁定更新以过渡到新版本。同样,当更改消息时,您只需提供旧版本,直到新版本可用。

然而,易于热插拔的代码仍然必须这样设计——应用程序必须足够模块化,以便替换组件的实现不会导致中断,而这只能来自仔细的编程。

The only thing that’s necessary to make this work is a form of dynamic binding, e.g., message passing in Erlang or eval in many other languages.

If you have dynamic binding, then you can change the target of a message without affecting the message, or a message without affecting the target—provided that a target is defined when you try to send a message to it, and a message is defined for the targets to which you send it, when you send it.

When changing a target, all you have to do is serve messages to the previous version until the new version is in place, then do a small locked update to transition to the new version. Similarly, when changing a message, you just serve the old version till the new one is available.

Readily hot-swappable code must still be designed as such, however—the application must be modular enough that replacing the implementation of a component does not cause an interruption, and that can only come from careful programming.

初见你 2024-12-18 20:51:41

在您的开发盒上进行“实时编码”固然很好,但直接与已部署服务器交互的方式使其更接近“真实”。为此,您需要一个网络感知的 REPL

clojure套接字复制。这允许您远程附加到部署的 tomcat 服务器上正在运行的代码版本(例如)。然后,您可以附加您最喜欢的支持 swank 的开发工具并进行破解。

It's well and good to have 'live coding' on your dev box, but a way to directly interact with a deployed server takes it a lot closer to being 'real'. For this you need a network aware REPL.

clojure provides this nicely in the form of a socket repl. This allows you to remotely attach to the running version of your code on your deployed tomcat server (for instance). You can then attach your favorite swank-enabled development tool and hack away.

沉默的熊 2024-12-18 20:51:41

Smalltalk 可能是最好的选择。与其他产品不同的是,它有一个用于实时编码的完整 IDE,而不仅仅是 REPL

Smalltalk is probably the best bet for this. As unlike the others, it has a whole IDE for live coding, not just a REPL

思念满溢 2024-12-18 20:51:41

Tcl已经有这样的东西了。例如,您可以编写一个 GUI 程序来创建一个具有交互式提示的单独窗口。从那里您可以重新加载代码、输入新代码等。

您可以使用任何 gui 工具包来完成此操作,尽管有些工具包会比其他工具包困难得多。使用 python 应该很容易,尽管缩进的事情——恕我直言——使得交互式使用具有挑战性。我相当确定大多数其他动态语言可以轻松做到这一点。

这样看:如果您的工具包允许您打开多个窗口,那么其中一个窗口就没有理由不能成为交互式提示。您所需要的只是打开一个窗口的能力,以及某种“eval”命令,该命令运行以字符串形式输入的代码。

Tcl has such a thing already. For example, you can write a gui program that creates a separate window that has an interactive prompt. From there you can reload your code, type in new code, etc.

You can do this with any gui toolkit, though some will be much harder than others. It should be easy with python, though the indentation thing -- IMHO -- makes interactive use challenging. I'm reasonably certain most other dynamic languages can do this without too much trouble.

Look at it this way: if your toolkit lets you open more than one window, there's no reason why one of those windows can't be an interactive prompt. All you need is the ability to open a window, and some sort of "eval" command that runs code fed to it as a string.

转瞬即逝 2024-12-18 20:51:41

google appengine 上的 python 有remote_api_shell.py。这不是一个完整的实时编码套件 - emacs 上的 clojure 和 swank-clojure 在将“实时编码”集成到日常开发节奏方面有更多的实际用途 - 但很多人没有意识到这是可能的在某些Python环境中。

$ PYTHONPATH=. remote_api_shell.py -s dustin-getz.appspot.com
App Engine remote_api shell
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)]
The db, users, urlfetch, and memcache modules are imported.

dustin-getz> import models
dustin-getz> models.BlogPost(title='a modern take on automated testing', link='https://docs.google.com/document/pub?id=1DUxQogBg45rOTK4c5_SfEHiQcvL5c207Ivcy-gDNx2s', dont_publish_feed=False).put()

dustin-getz> items = models.BlogPost.all().filter('dont_publish_feed =', False).order('-published_date').fetch(100)

dustin-getz> len(items)
58

dustin-getz> for item in items[:5]: print item.title
a modern take on automated testing
Notes: Running a startup on haskell
the [un]necessity of superstar middle management in bigcos
"everything priced above its proper value"
stages of growth as a software engineer

python on google appengine has repote_api_shell.py. this is not a full live-coding suite - clojure on emacs w/ swank-clojure has had much more real-life use as far as integrating 'livecoding' into everyday development rhythms - but a lot of people don't realize this is possible in certain python environments.

$ PYTHONPATH=. remote_api_shell.py -s dustin-getz.appspot.com
App Engine remote_api shell
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)]
The db, users, urlfetch, and memcache modules are imported.

dustin-getz> import models
dustin-getz> models.BlogPost(title='a modern take on automated testing', link='https://docs.google.com/document/pub?id=1DUxQogBg45rOTK4c5_SfEHiQcvL5c207Ivcy-gDNx2s', dont_publish_feed=False).put()

dustin-getz> items = models.BlogPost.all().filter('dont_publish_feed =', False).order('-published_date').fetch(100)

dustin-getz> len(items)
58

dustin-getz> for item in items[:5]: print item.title
a modern take on automated testing
Notes: Running a startup on haskell
the [un]necessity of superstar middle management in bigcos
"everything priced above its proper value"
stages of growth as a software engineer
趁年轻赶紧闹 2024-12-18 20:51:41

我正在为 PyDev 的 Python 编辑器开发实时编码功能。它的灵感来自于 Bret Victor 的 Inventing on Principle talk,我已经实现了一个程序状态显示以及海龟图形。当您在 Eclipse 中键入 Python 代码时,它们都会更新。

该项目托管在 GitHub 上,我已经发布了 演示视频,以及 教程

我使用的Python的主要特性是抽象语法树和动态代码执行。我获取用户的代码,将其解析为树,然后检测任何赋值语句、循环迭代和函数调用。一旦我对树进行了检测,我就会执行它并显示报告或绘制所需的海龟图形。

我还没有实现其他答案讨论的交换功能。相反,我总是运行代码直至完成或超时。我认为实时编码是测试驱动开发的增强,而不是破解实时应用程序的一种方式。然而,我会更多地考虑更换实时应用程序的各个部分可以让我做什么。

I'm working on a live coding feature for PyDev's Python editor. It was inspired by Bret Victor's Inventing on Principle talk, and I've implemented a program state display as well as turtle graphics. They both update as you type your Python code in Eclipse.

The project is hosted on GitHub, and I've posted a demo video, as well as a tutorial.

The main features of Python that I used were abstract syntax trees and dynamic code execution. I take the user's code, parse it into a tree, then instrument any assignment statements, loop iterations, and function calls. Once I've instrumented the tree, I execute it and display the report or draw the requested turtle graphics.

I haven't implemented the swapping feature that other answers discuss. Instead, I always run the code to completion or a time out. I envision live coding as an enhancement to test-driven development, not as a way to hack on a live application. However, I will think more about what swapping out pieces of a live application would let me do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文