Writing extensions
As already said, writing extensions is not a simple task but in exchange for your hard work, it can give you a lot of advantages. The easiest and recommended approach to your own extensions is to use tools such as Cython or Pyrex or simply integrate the existing dynamic libraries with ctypes
or cffi
. These projects will increase your productivity and also make code easier to develop, read, and maintain.
Anyway, if you are new to this topic, it is good to know that you can start your adventure with extensions by writing one using nothing more than bare C code and Python/C API. This will improve your understanding of how extensions work and will also help you to appreciate the advantages of alternative solutions. For the sake of simplicity, we will take a simple algorithmic problem as an example and try to implement it using three different approaches:
Writing a pure C extension
Using Cython
Using Pyrex
Our problem will be finding the nth number of the Fibonacci sequence. It...