Give a Reusable Calculation a Clear Contract

Copying a calculation into every exercise makes mistakes hard to repair. We will put the rule in a function, state what its inputs mean, and check it on more than one report.

10 sections · 4 questions · 2 coding challenges

1 / 10

Making Numerical Routines Reusable Without Losing Their Assumptions

BOTIE

Reusable numerical routines let programmers test one implementation and call it from many calculations. Their usefulness depends on the caller and the routine agreeing about dimensions, units, and valid inputs.

NumPy's array conversion and testing interfaces support those contracts. They let a Python function accept array-like input, validate its layout, and compare a result with a small independently checked example. The function remains responsible for its scientific assumptions.

Sources for this history