A good API:
f = ddot(1000, vector_a, 1, vector_b, 1)
Another example: we program our own bank:
bank_new()
bank_deposit(100.0)
bank_deposit(100.0)
bank_withdraw(50.0)
my_balance = bank_get_balance()
bank_free()
Problem: We have to close the account before opening a new one.
It would be great to have more contexts:
account1 = bank_new()
bank_deposit(account1, 100.0)
bank_deposit(account1, 100.0)
account2 = bank_new()
bank_deposit(account2, 200.0)
bank_deposit(account2, 200.0)
bank_withdraw(account1, 50.0)
balance1 = bank_get_balance(account1)
balance2 = bank_get_balance(account2)
bank_free(account1)
bank_free(account2)
fftw_complex in[N], out[N];
fftw_plan p;
...
p = fftw_create_plan(N, FFTW_FORWARD, FFTW_ESTIMATE);
...
fftw_one(p, in, out);
...
fftw_destroy_plan(p);
Discuss with the group other examples
.
|-- CMakeLists.txt
|-- LICENSE
|-- README.md
|-- api
| |-- cffi_helpers.py (CFFI boilerplate code)
| |-- example.h (C interface)
| `-- example.py (Python interface)
|-- requirements.txt
|-- src
| |-- bank.cpp (C++ library)
| |-- bank.f90 (Fortran library)
| `-- bank.h (C++ library)
`-- test
|-- test.cpp (C++ client)
|-- test.f90 (Fortran client)
`-- test.py (Python client)
def deposit(account, amount):
deposit_explicit(account=account,
amount=amount,
currency='EUR',
date=today(),
message='standard deposit',
...)
def deposit_explicit(account, amount, currency, date, message, ...):
...
Encapsulate.
Take some time to design an API.
Document and version your API.