Rust for Domain Experts

Introduction

Over the past few years I have been writing more and more Rust code. I have been using Python for many years, it's a great language, and I am very productive in it. However, I have come to the conclusion that Rust is a really strong candidate for domain experts to learn. By domain expert I mean someone who does not have a formal computer science background. I'm in this category, my domain being Actuarial Modeling. I will refer to Actuaries below, but you can insert your domain if you are in the same boat as I believe the arguments apply across domains.

But isn't Python good enough?

Python is a fantastic tool and language. I feel I owe a lot to Python and the community that supports it. In my initial years working as an Actuary I was always drawn to the more technical roles, especially with regard to technology. For any new Actuary without any knowledge of programming or computer science this meant bending Microsoft Excel to do things it was never designed to do.

I then started to work on a product then embedded Python, I had the Python interpreter and standard library at my finger-tips. This was an amazing period of exploration. It was like a whole new world opened up for me. I started to realize the power of a "proper" programming language. Over the next few years I became quite proficient in Python and I loved the power that came with it. I felt I was able to hack on anything I wanted, and it was quite addicting. Sometimes I would solve certain problems in a certain way just to use feature X or challenge myself. I have come a long way in my Python journey and over time I invested in learning to fill in the holes in my skills with regard to software development.

Python can be used to build larger software systems that need to be performant, i.e. Actuarial Modeling, but as with most things in life you are making a trade off. Python is too easy in some sense. People copy and paste code that uses (insert-new-machine-learning-framework) and just go from there. In reality, it takes an investment in the basics of software development to really learn it correctly, or more accurately learn how to manage it correctly. When I write large systems in Python now it feels a little like taking out a loan. I can have that instant satisfaction of building something fast, but I know that I'm going to have to pay for it down the line in the form of maintenance.

Another drawback is when you hit the performance barrier in Python. All the high performance libraries in Python are written in C/C++ but every so often your problem does not fit into the paradigm that these libraries use (typically array processing). At this point you're out of luck, you can invest in numba, Cython, etc. but they bring their own complexity and trade-offs.

Rust is too hard for Actuaries to learn

There is no denying that Rust is more difficult to learn than Python, but let's not sell the Actuarial profession short here. Actuaries spend years studying complex topics, it's well within their reach to learn Rust. In general, I don't feel that Actuaries embrace programming as much as they should. Quants embrace programming and go head first into C++ of all things, I would love to have Actuaries take this approach also, i.e. the mind-set not C++...

I prefer to look at Rust as enforcing standards, i.e. quality at the source. Yes, you will get frustrated but once it complies generally it works. Also, once it complies there are whole classes of bugs that are ruled out, the kinds of bugs that you always remember to write tests for in Python, right? Rust is blazing fast and complies to a single binary meaning that deployment is simple. Hand over the .exe and it runs, no more serving as the Python install help desk within your team.

The biggest win for Rust though is that in return for the upfront investment you create systems that are far more robust and easier to maintain. When you build a large system in Python it's easy to build because you have the whole system in your mind while you are working on it. However, coming back to said system years later and making changes can be difficult especially if others have been developing it since then. The Rust compiler is the ultimate code reviewer ensuring that everyone is keeping up their standards.

A short note on C++

Yes - this actually is too hard to learn for Actuaries (in general). In order to learn C++ you really need to immerse yourself in it. There is no other way, the language is too big (something I hope does not happen Rust). You have to learn the concepts encoded in the Rust borrow checker as good coding practice.

Where do I sign-up?

After all this would I recommend using Rust today, yes I would. However, it will still feel like you are an "early adopter" the point of this post is that I see it being a far more attractive option in Actuarial Modeling in the future. Like all software, great abstractions can reduce the barrier to entry and increase productivity. At the moment, you kind of need to "roll your own" for a lot of things. I think that once some foundational Actuarial Modeling libraries are in place Rust will be a great option for Actuaries and Actuarial Modeling in particular. My involvement in the Apache Arrow project has been motivated with this goal in mind. More to come on that.... I hope :)

Avatar
Paddy Horan
Actuarial Technology Lead

Technology Actuary and leader who loves solving interesting problems.