哪些现有语言功能最难实现?为什么?
看着一些语言功能,我有时想知道到底有人会如何实现这样的功能。所以我的问题是,众多现有语言功能中哪一个最难实现?最受欢迎的解释是为什么会这样(甚至可能是必需的?)。
为了维持秩序,每个帖子只能有一个专题。
Looking at some language features I sometimes wonder how on earth would someone implement a functionality like this. So my question is, which of the numerous existing language features are the hardest to implement? An explanation why is it so is most welcome (maybe even required?).
To maintain order, please only one feature per post.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MHMH - 这个问题以前没有被问过吗?
高效的封闭处理。
由于 Lisp 和 Smalltalk(在那里称为“Block”)中使用闭包的频率远高于几乎任何其他编程语言,因此实现必须非常快。所以堆栈分配就是我们想要的速度。但是,由于“真正的”闭包可能比其定义的方法堆栈框架寿命更长,因此必须注意在需要时将它们从堆栈中取出。
闭包在任何地方都很有用:回调、枚举/集合协议、长跳转、动作工作队列、观察者协议、延迟评估(future 和lazy)等等。
顺便说一句:JavaScript 也支持闭包!
MHMH - hasn't this been asked before ?
Efficient closure handling.
As closures are used in Lisp and Smalltalk (called "Block" there) MUCH more often than in almost any other programming language, the implementation has to be very fast. So stack allocation is what we want for speed. But, as "real" closures can outlive their defining method-stack frame, care must be taken to get them off the stack if required.
Closures are useful everywhere: callbacks, enumeration/collection protocols, longjumps, action-worker queues, observer protocols, delayed evaluation (futures and lazy) and many more.
BTW: JavaScript also supports closures !
即使是最奇怪和最复杂的语言功能,例如 C++ 模板,实际上也相对容易实现。真正困难的是有效地实现这些功能。
对我来说,最难的功能是使用类似 ML 的语言进行柯里化。对于临时实现来说微不足道,如果您希望它在库存硬件上高效,那就非常棘手了。有关详细信息,请参阅任何合适的 ML 实现。
Even the most weird and complex language features, such as C++ templates, are actually relatively easy to implement. What is really hard is to implement those features efficiently.
For me the hardest feature was currying in ML-like languages. Trivial for an ad hoc implementation, it is quite tricky if you want it to be efficient on a stock hardware. See any decent ML implementation for details.