What is the difference between a wrapper, a binding, and a port?
Asked Answered
L

2

40

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?

Lilli answered 25/12, 2011 at 5:15 Comment(1)
It's impossible to tell what you're talking about unless you give more context.Nephrectomy
R
75

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.
Requirement answered 25/12, 2011 at 6:14 Comment(3)
Does wrapper have significant performance hit? Should i use wrapper in a benchmark application where performance is important?Isobel
Every wrapper is a "performance hit" because you're effectively handing off data to another process and waiting for it to return. The upside is that if you're handing off to something way faster, the hit may be balanced out by the gains! An example coming to mind is the Hekad project written in go includes a lua interpreter to execute a C regex wrapper.... which is faster than go's native regex handler ATM.Requirement
//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.)// You mean binding right? You may need to write bindings for the functionality that's missing.Estival
A
1

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.

Alysa answered 28/12, 2011 at 12:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.