[r-t] Writing method display software

Leigh Simpson lists at simpleigh.com
Thu Dec 3 21:50:25 UTC 2015


Aye,

> I can't remember whether it has been mentioned in the context of this
> conversation, but there is a set of Python bindings for the Ringing Class
> Library at https://github.com/ringing-lib/ringing-lib-python.

It's probably worth saying a little more about this. The Ringing Class
Library is pretty fantastic, but arguably suffers from the disadvantage of
being written in C++. The development of the web has brought an explosion of
interest in scripting languages like Python, PHP and JavaScript. C++ is a
perfectly appropriate choice for a library implementation but isn't
particularly accessible to novice programmers, and I'd been thinking for a
while that it'd be worth writing a wrapper for the library in something more
high-level. I've toyed with PHP extension writing before - enough to know
this would be a fairly painful process, but luckily a change at work into
Python coincided with my discovery of Cython [1].

Cython transpiles Python syntax into a C or C++ source that can be compiled
into a Python extension. Simply using it makes code run faster, but it's
then possible to get more speed by adding type annotations in order to start
using native C or C++ types (e.g. C strings or raw integers) rather than
Python ones. More importantly it also provides good support for calling
external libraries.

Wrapping an external C++ class becomes a pretty simple process [2]:

1. Find the header file of the class you want to wrap
 
https://github.com/ringing-lib/ringing-lib/blob/f95f8e6/ringing/row.h#L76-L1
58

2. Translate the header file into a Cython pxd file:
 
https://github.com/ringing-lib/ringing-lib-python/blob/5a42c46/src/row.pxd
   This isn't too hard - the code looks a lot like the original header file 

3. Implement a class in pseudo-Python to call into a contained C++ class:
 
https://github.com/ringing-lib/ringing-lib-python/blob/5a42c46/src/row.pxi
   My Python "Row" class contains a C++ "row" class (cdef row *thisptr), and
each method calls through to the underlying implementation.

4. Spend more time writing unit tests and documentation than went into the
implementation!

So far I've implemented the following classes from the Ringing Class
Library: Bell, Row, Group, Change, RowBlock and Method, so there's still
some way to go. Nevertheless this is enough to string together simple touch
searches. Hopefully there's potential here to blend the clarity of Python
with the speed of the underlying C++ implementation.

If you have a working implementation of the Ringing Class Library (i.e. your
*nix system can find the headers and libraries), a working gcc and Python
headers then it should be possible to install the Python wrappers from PyPI
using pip [3].

    Source code is on GitHub at
https://github.com/ringing-lib/ringing-lib-python - pull requests very
welcome.
    Documentation is at http://ringing-lib-python.readthedocs.org/
    The Ringing Class Library itself is now on GitHub too at
https://github.com/ringing-lib/ringing-lib
    ... and its website has moved to http://ringing-lib.github.io/ (although
there's still stuff on SourceForge).

Best wishes,

Leigh

[1] http://cython.org/
[2] See http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html for
more detail
[3] https://pypi.python.org/pypi/ringing-lib/






More information about the ringing-theory mailing list