2 "Best Practices" Posts

Python Tip of the Week: Try SymPy When NumPy Isn't Enough

Most of us reach for NumPy whenever math shows up in a project. But sometimes, you don’t want approximate answers, you want exact math. That’s when you pull SymPy out of your programmer’s toolkit and get to work.

It’s easy to think of SymPy only in academic terms, like running physics simulations where small rounding errors can snowball into nonsense, or checking algebraic identities where a value such as 0.0000001 should really be treated as exactly 0. Those are valid use cases, but they barely scratch the surface.

In real-world business applications, imprecision can be just as costly. Financial software is the most obvious example, where a few pennies lost to rounding errors can add up to millions at scale. Supply chain and logistics systems can also suffer when tolerances or unit conversions drift slightly off, leading to incorrect shipments or mismatched inventory. Even common scenarios such as pricing models or tax calculations can go sideways if the math behind them is not exact.


“Floats guess. SymPy knows.”


This is where SymPy shines. To see the difference between floating-point approximations (Python or NumPy) and symbolic precision (SymPy), let’s look at a simple but very real example from finance.

Read more →

Python Tip of the Week: Using Dispatch Tables for Cleaner Validation

Let’s be honest: argument validation code is rarely the proudest part of anyone’s repo.

Most of us start with the usual suspects:

❌ The dreaded inverted-V tower of if/else statements
❌ A graveyard of guard clauses scattered line after line


Using a dispatch table for validation rules means: one dictionary, one loop, infinite sanity.


Both work fine… until they don’t. Then you’re left maintaining a wall of conditionals that feels like it was designed by a committee of goblins.

There’s a better way: dispatch tables!

Read more →