Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decide when to wrap/port/write-from-scratch

There is a project I'm about to build in Smalltalk (Pharo). And there is a python library which I intend to use for the same. Now, there are 3 options:

  • Smalltalk wrapper for those python libraries
  • Porting the python library to Smalltalk
  • Write the library from scratch (in Smalltalk) for use in my project

The following are my queries:

  1. What are 'basic' differences in porting/wrapping (No satisfactory explanation found anywhere yet)
  2. How to know when to use which (of all the three)?
  3. Any resources or pointers where I can get further help/some kick-start into my project.

Thanks!

like image 892
zalenix Avatar asked Dec 17 '22 01:12

zalenix


1 Answers

Wrapper

Write functions in the native language whose sole purpose is to call the functions in the external library. The goal is to do as little as possible in the native language. For example, translating data types from the native language to the external library language, etc.

Wrappers make sense when the external library is:

  • written in a more efficient language than the native code (eg, a C++ library called from Python)
  • large/complex and would be time-consuming or error prone to translate
  • regularly updated; in a well-maintained library the interfaces (what your wrapper is concerned with) will change less often than the implementation of the features; so if you have wrappers around the functionality, updating to a new version of the library should be fairly straightforward

Porting

A port is simply a translation from one language to another. In general, the same logic is maintained as much as possible.

Porting makes sense when:

  • the native language is more efficient than the external library
  • the library is simple and one wants to save on the overhead involved with wrapping
  • one intends to make and maintain changes to the ported code in the native language
  • there are no plans to use the external library in its own language
  • one wants to learn one or both of the languages involved

Re-Write

Think of a Re-Write as a Port with a lot of refactoring. The goal is to take advantage of features of the native language to improve the library in some way (efficiency, readability, etc.)

Re-Writing makes sense in all of the same scenarios as porting. Deciding whether to do a simple port or a full re-write usually comes down to one question:

  • Is there a better way to implement the features of the external library in the native language?
like image 106
mwolfe02 Avatar answered Dec 26 '22 16:12

mwolfe02