Exec Summary
Many businesses rely on calculations and code that are poorly written, un(der)-documented, or simply relics of an earlier era. These hidden assets often underpin critical operations, yet their full value is locked away—difficult to maintain, understand, or adapt as business needs evolve.
In this post, I share how I tackled a classic engineering calculation. My approach goes beyond just getting the maths right: I review, refactor, and extend a simple “bubble-cosh” script, transforming it into a robust, maintainable, and user-friendly solution. Along the way, I demonstrate best-practice software engineering, clear validation, and a focus on delivering solutions that are mathematically sound, practically usable, and visually engaging for users, thus unlocking new business value from old or messy code.
Why Revisit the Catenary Problem?
Catenary curves underpin a surprising range of engineering applications, from the design of overhead cables to architectural arches. While the underlying mathematics is well-established, the practical implementation (especially in code) can be fraught with pitfalls: transcendental equations, edge cases, and the ever-present risk of misapplying formulas.
As with any engineering tool, reliability and clarity are paramount. I set out to review a legacy script, apply modern Python best practices, and make the solution accessible via both command-line and interactive notebook interfaces.
Reviving Value from Legacy and Proprietary Code
As a quick aside, I specialise in working with legacy and proprietary codebases that are often:
- Poorly documented or written in outdated styles
- Hidden intellectual property critical to business operations
- Difficult to maintain as experienced programmers become scarce
My approach focuses on:
- Thoroughly reviewing and understanding existing code
- Applying modern software engineering practices and clear documentation
- Re-engineering to make code maintainable, accessible, and ready for integration
This process not only preserves original value but also breathes new life into existing investments—a vital capability as the pool of skilled programmers continues to shrink. Any COBOL
programmers out there? Reviving and modernising legacy code ensures business continuity and unlocks innovation potential.
This is a common scenario in many industries: you have a codebase that’s critical to your operations, but it’s poorly documented, written in outdated styles, or simply not maintainable. Engaging a multi-language (i.e. Python, SQL, C/C++, C#, MATLAB, VBA, even Fortran!), multi-discipline expert is essential for such projects to achieve great results.
The caternary example for this post is a simple representative example of the kind of problems I observe and how I approach them.
Review and Refactor: My Approach
1. Understand the Problem and the Code
First, I reviewed the original code, its assumptions, and the mathematical background. I checked the implementation against trusted sources (Wikipedia, MathWorld, engineering texts) and clarified the limits of the formulas—especially around transcendental solutions and practical engineering constraints.
2. Refactor for Clarity and Reuse
- Encapsulation: The procedural code was refactored into a
Catenary
class, encapsulating all calculations and properties. - Validation: I implemented robust parameter validation, ensuring that physical and mathematical constraints are respected.
- Documentation: Succinct, docstrings and comments clarify intent and usage throughout.
3. Add Multiple Interfaces
- Command-Line Tool: Using Python’s
argparse
, I built a CLI so calculations can be directly from the terminal, specifying diameter and span as arguments. - Interactive Notebooks: User-Friendly UIs as a Core Deliverable.
Interactive Notebooks
A major part of my approach is ensuring that technical solutions aren’t just mathematically correct, but also accessible and engaging for business end users. Too often, interactivity and user experience are bolted on at the end, if at all. I believe that building a user-friendly interface is an integral part of the delivery, not an optional extra.
For this project, I chose Marimo, a next-generation Python notebook that allows you to bind UI elements—like sliders, dropdowns, and interactive plots—directly to your Python logic. This means business users and stakeholders can explore scenarios, tweak parameters, and visualise results in real time, all without touching a line of code.
With Marimo, the catenary calculation isn’t just a static formula or a black-box script. Instead, it becomes a living, interactive model. Users can:
- Adjust the span or diameter with a slider and instantly see how the curve changes.
- Explore the impact of engineering constraints visually, not just in numbers.
- Export or share the notebook as an interactive web app, making collaboration seamless.
By designing the UI and interactivity from the outset, I ensure that:
- Business users are engaged early: they can provide feedback, ask “what if?” questions, and see the results for themselves.
- The solution is robust and transparent: inputs, outputs, and assumptions are clear to everyone, not just the developers.
- Delivery is faster and more effective: because the interface is built alongside the logic, not tacked on at the end.
This approach isn’t just about making things look pretty. It’s about bridging the gap between complex logic and practical business decision-making. By making the model interactive and user-friendly, I help businesses get more value from their data and calculation-driven workflows, and ensure that solutions are actually used, not just "delivered".
Here is a link to the live Marimo notebook. For those used to static reports or PDFs, think of Marimo notebooks as a modern, interactive upgrade that lets you explore information interactively and at your own pace. Note that you can hide/show the underlying code in the notebook by clicking the three dots in the top right hand corner of the page.
Of course Marimo is just one option; there are many other tools and frameworks that can achieve similar results - for example: Streamlit, Gradio and many others, or even custom web applications depending on the use case(s). The key takeaway is that interactivity and user engagement should be core to any technical solution, not an afterthought.
Final Thoughts
This exercise reinforced the value of combining mathematical rigour with software engineering best practice. By reviewing, refactoring, and extending legacy code, I’ve delivered a solution that’s not only correct, but usable, maintainable, and ready for real-world engineering challenges. Space constraints prevent me from discussing testing via pytest
tests in this post.
If you’re looking to modernise your engineering calculations, automate legacy workflows, or simply want code you can trust, I’d love to chat.
Appendix: Technical Deep Dive
Key Features of the New Solution
- Robust Parameter Fitting: The core challenge—solving for the catenary’s parameters given endpoints and sag is handled via a numerically stable search, with configurable precision.
- Geometric Properties at a Glance: The class provides instant access to area under the curve, midpoint dip, and gap, supporting both design and validation workflows.
- Flexible Output: Whether you want a CLI summary or a Markdown report for your notebook, the solution adapts to your workflow.
- Interactive Visualisation: Sensible default plotting with configurable axes and real-time updates in the notebook.
Observations and Lessons
- Grounding in Reality: Mathematical solutions sometimes diverge from practical engineering needs. For example, while the span/diameter ratio can be made arbitrarily large in theory, real-world constraints (material strength, safety) demand explicit limits.
- Clarity Over Cleverness: Encapsulating the maths in a class, with clear docstrings and outputs, makes the code maintainable and accessible to both engineers and analysts.
- Modern Tooling: Leveraging tools like Marimo for notebooks and
argparse
for CLI interfaces ensures the solution is both interactive and scriptable, meeting users where they are. - User Engagement: Integrating UI design from the start ensures business users are actively involved, improving adoption and impact.