Smalltalk如何处理程序错误?

发布于 2024-11-15 05:50:45 字数 208 浏览 2 评论 0原文

我是 Smalltalk 的新手。我读过一些关于它的文章和文档,我对其概念的完整性感到惊讶。它提供某种实时调试。

不管怎样,对于程序错误来说,错误意味着程序逻辑错误,程序累积的所有突变都无效。为了保证完整性,整个程序应该从某个点重新启动,并且整个程序状态应该回滚。

Smalltalk 如何处理这个问题? (也许这个问题可以适用于所有动态 REPL 语言......)

I'm a newbie on Smalltalk. I have read some articles and documents about it and I am surprised about its completeness of concepts. And it offers some kind of live debugging.

Anyway, for program errors, the error means the program logic is wrong, and all accumulated mutations by the program are all invalid. To guarantee integrity, the whole program should be restarted from some point, and the whole program state should be rollback.

How does Smalltalk handle this? (maybe this question can be applied to all dynamic REPL languages...)

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

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

发布评论

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

评论(4

不喜欢何必死缠烂打 2024-11-22 05:50:45

Smalltalk 使用 Exception 对象。我建议您阅读有关 的章节https://gforge.inria.fr/frs/download.php/26600/PBE2-Exceptions-2010-03-02.pdf

它是Pharo By Example 书:http://pharobyexample.org/

关于突变、调试等,请注意 Smalltalk 具体化了很多语言中的东西。例如,MethodContext 类。这些对象代表虚拟机正在执行的方法上下文。因此您可以像对待普通物体一样检查它们并玩耍它们。与 CompiledMethod 相同。只是为了好玩,检查“伪”变量“thisContext”:)

如果您想自己回答您的答案,请查看 Debugger 类。那么,您想知道在调试器中间重新启动该方法时会发生什么吗?然后在调试器中浏览方法 #restart 并按照:)

Smalltalk uses Exception objects. I recommend you to read the chapter about that https://gforge.inria.fr/frs/download.php/26600/PBE2-Exceptions-2010-03-02.pdf

it is part of the Pharo By Example book: http://pharobyexample.org/

Regarding the mutation, debugging, etc, note that Smalltalk reifies lot of stuff in the language. For example, the MethodContext class. Those objects reprents the method contexts that the VM is executing. So you can inspect them, and play with them just as a regular objects. The same with CompiledMethod. Just for fun, inspect the "pseudo" variable 'thisContext' :)

IF you want to answer your answers yourself, take a look to the Debugger class. So, do you want to know what happens when you restart the method in the middle of the debugger? then browse the method #restart in Debugger and follow :)

笑忘罢 2024-11-22 05:50:45

实际上,您是在问“整个计算机如何回滚到已知状态?”,因为 Smalltalk 映像与 VMWare 和 VirtualBox 是相同意义上的虚拟机。

我们最接近消除任意副作用的能力(不包括回滚 I/O 等明显不可能的情况)可能是 Alessandro Warth 的世界,正如他的博士论文使用编程语言进行实验。至少在一般意义上:当然可以使用诸如 Memento 和 Command 模式之类的东西来实现可撤消的操作。

You're asking, in effect, "how can this entire computer roll back to a known state?", because a Smalltalk image is a virtual machine in same sense that VMWare and VirtualBox are.

The closest that we have to the ability to undo arbitrary side effects (excluding obvious impossibilities like rolling back I/O) is probably Alessandro Warth's Worlds, as described in his PhD thesis Experimenting with Programming Languages. At least in a generic sense: it's of course possible to use things like the Memento and Command patterns to implement undoable operations.

傲性难收 2024-11-22 05:50:45

我猜您指的是图像中的许多对象,这些对象在开发和调试时可能会进入不一致的状态。通常的过程是将代码存储在包中,例如(Monticello for squeak/pharo)。当您想要重置时,您可以从发行版中获得一个干净的映像,并从包中重新加载代码。对于已部署的应用程序,除了包中的代码之外,您通常还需要重新创建以某种外部形式存储的数据对象所需的信息,例如存储在文件中或 dql 或 noSql 数据库中的序列化形式。因此,您的重置过程将采用新图像,从包中加载代码,从外部存储加载数据模型对象。

I guess you are referring to a lot of objects in the image that can get into inconsistent state while developing and debugging. Usual procedure is to store code in packages like (Monticello for squeak/pharo). When you want to reset things, you would get a clean image from the distribution and reload code from the packages. For deployed applications in addition to code in the packages, you would usually have information needed to recreate your data objects stored in some external form like serialized form stored in the files, or in dql or noSql database. So your reset procedure would be take fresh image, load code from the packages, load your data model objects from external store.

赢得她心 2024-11-22 05:50:45

事实并非如此!

从smalltalks我知道他们都不支持这种交易。设置执行期间累积的所有副作用。不支持自动回滚。目前正在研究如何支持这一点,但据我所知没有什么可尝试的。您必须知道,如果您正在调试并且返回堆栈跟踪,则对象并不处于执行时的状态。您只能看到最新状态的对象。

虽然以通用方式支持这一点并不容易,但有一些可能性可以通过程序的设计来解决这个问题。最突出的方法是:

  • 复制/克隆要修改的对象并将更改应用到副本。如果出现问题,您只需扔掉副本即可。如果一切正常,您可以将副本的内容应用于原件。您可以使用备忘录模式来解决这个问题。
  • 您将更改应用于对象,但如果出现问题,您将重新应用原始内容。可以使用命令模式通过执行/撤消操作来实现

It doesn't!

From the smalltalks I know none of them supports this kind of transaction. All side effects that are accumulated during execution are set. There is no supported automatic rollback. There is research undergoing how to support this but nothing to try out AFAIK. It is something you have to know that if you are debugging and you go back in the stack trace that the objects aren't in the state they were at execution time. You see just the objects in their newest state.

While it is not that easy to support this in a generic fashion there are some possibilities to solve this with the design of your program. The most prominent approaches are:

  • you copy/clone the objects you want to modify and apply the changes to the copies. If something goes wrong you just throw away the copies. If everything is fine you apply the content of the copies to the originals. You can solve this using the memento pattern.
  • you apply changes to your objects but if something goes wrong you re-apply the original content. That can be implemented with do/undo actions using the command pattern
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文