包装器、绑定和端口之间有什么区别?

发布于 2024-12-22 14:04:39 字数 238 浏览 0 评论 0原文

在软件可移植性背景下,这三个概念之间有什么区别?

比如我想使用ncurses库,原来的ncurses库是用C写的,但是我的应用程序是用 C++ 编写的,然后我找到了“ncurses 包装器”、“ncurses 的绑定”和“ncurses 端口”。我应该使用哪一个?

每一种的优点和缺点是什么?

In a software portability context, what is the difference between these three concepts?

For example, I want to use the ncurses library, the original ncurses library is written in C, but my application is being written in C++, and then I found "ncurses wrapper", "bindings to ncurses", and "ncurses port". Which one should I use?

What are the pros and cons of each one?

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

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

发布评论

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

评论(2

亢潮 2024-12-29 14:04:39

wrapper 是一段位于其他代码之上的代码,用于回收其功能,但具有不同的界面。这通常意味着用相同语言编写的界面。还应该注意的是,有时人们会说包装器,而他们在技术上的意思是绑定(包括我自己)。

优点:

  • 它与原始
  • 包装器使用相同的语言,增强或重用功能,而不需要完全重写。
  • 相对较快地完成
  • 当源库发生变化时, 琐碎的更新。您可能只需要绑定新函数,除非它们通过更改函数/类的预期输入/输出来破坏向后兼容性。

缺点:

  • 包装整个库可能会非常重复

绑定 是位于顶部的另一段代码其他代码来回收它的功能,除了这次绑定是用与它们绑定的东西不同的语言编写的。一个值得注意的例子是 PyQt,它是 QT 的 python 绑定。

优点:

  • 将另一种语言的功能引入您选择的语言中。
  • 与端口相比相对较快
  • 需要与包装相同级别的琐碎更改 - 您可能只需要包装新函数/类,除非它们通过更改函数/类的预期输入/输出来破坏向后兼容性。

缺点:

  • 与包装器一样重复
  • 您可能会受到相当大的性能影响,尤其是任何一端涉及解释语言的包装器

Port 是指您将某些代码翻译为在不同的环境中工作。常见的类比包括针对 Xbox 推出的游戏,后来又针对 PS3 发布。

优点:

  • 当您发现不足之处时,让您有机会改进代码库
  • 您将非常熟悉代码的运行方式,而不仅仅是它的作用。

缺点:

  • 到目前为止,就时间而言最长的解决方案/需要完全重写
  • 您需要确保源库在某种语言中需要的任何功能在您的目标端口语言中都可用,否则您最终将包装所需的功能(并且可能达不到目的。)
  • 每次源库更新时,您也必须通过翻译它们所做的任何更改来进行更新,否则就有落后的风险。

A wrapper is a bit of code that sits on top of other code to recycle it's functionality but with a different interface. This usually implies an interface written in the same language. It should also be noted that sometimes people will say wrapper when what they technically mean is a binding (myself included).

Pros:

  • It's in the same language as the original
  • Wrappers enhance or reuse functionality without needing a full rewrite.
  • Relatively quick to accomplish
  • Trivial updates when the source library changes. You'll probably only need to bind new functions unless they broke backwards compatibility by changing expected input/outputs of functions/classes.

Cons:

  • Wrapping an entire library can be extremely repetitive

A binding is another bit of code that sits on top of other code to recycle it's functionality except this time bindings are written in a language different than the thing they bind. A notable example is PyQt which is the python binding for QT.

Pros:

  • Bring functionality from another language into the language of your choice.
  • Relatively fast in comparison to a port
  • Same level of trivial changes are needed as in wrapping- You'll probably only need to wrap new functions/classes unless they broke backwards compatibility by changing expected input/outputs of functions/classes.

Cons:

  • Just as repetitive as a wrapper
  • You're probably taking a fairly large performance hit, especially any wrapper involving an interpreted language on either end

A Port is when you translate some code to work in a different environment. Common analogies include games that come out for say... XBox and are later released for PS3.

Pros:

  • Gives you the opportunity to make improvements to the code base as you see inadequacies
  • You'll be intimately familiar with HOW the code runs, not just what it does.

Cons:

  • By far the lengthiest solution in terms of time/requires a complete rewrite
  • You need to make sure that whatever functionality the source library needs in a language is available in your target port language or you'll end up wrapping needed functionality (and potentially defeating the purpose.)
  • Every time the source library updates, you have to update too by translating whatever changes they made or risk falling behind.
半﹌身腐败 2024-12-29 14:04:39

我应该使用哪一个?

您应该使用ncurses 绑定。绑定是应用程序、库等的特定版本,它与原始版本的不同之处仅在于您可以将其与其他语言一起使用。常见的例子包括窗口管理器(gtk+ = C、gtkmm = C++;Qt = C++、PyQt = Python;ecc)。然而,人们经常使用包装器或端口等其他词来指代绑定,因此很容易让自己感到困惑。

Which one should I use?

You should use bindings to ncurses. A binding is a particular verion of an application, library, etc. that differs from the original only beacuse you can use it with another language. Frequent examples include windows managers (gtk+ = C, gtkmm = C++; Qt = C++, PyQt = Python; ecc.). However, people often use other words like wrapper or port to refer to bindings, so it's easy to get yourself confused.

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