I need to share some financial formulas across the backend and the frontend. One way of doing this would be to make AJAX calls to the server to get the results, but we want to avoid this as we want our UI to show immediate feedback.
At the moment we are using Ruby and Javascript, and I have a solution working where the formulas are written in JS and Ruby calls Node to run the formulas on the server.
I would like to find something that is more language agnostic, as we may start using Go on the backend.
I am thinking that a DSL or some kind of mini-language could be used in both places, but haven't found one yet. Do you know any DSLs for financial formulas? Or maybe a mini-language that can be run from Javascript and Ruby?
Since your constraint is that the formula runs both locally in the browser and on the server, you're stuck with the intersection of languages that compile to, or can be interpreted by, both js and your desired server language (in this case Go) - which is basically nothing.
IMO your current approach makes perfect sense - why not continue using node? You have a pretty much perfect separation of concerns with the formula code.
If it's a performance issue, check out this list of other server languages that can compile to js
Of these, I like the Haxe project, but unfortunately it doesn't target Go. And it also adds a layer of abstraction that your current approach doesn't have or need.
If you want to use a scripting language instead of a compilation target you could write the formulas in Lua - which is available as a scripting language in the browser if you include the Lua VM and also on your server in Go using C bindings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With