My recipe for converting from one language to another is quite simple, at least when the second language is able to fully wrap the first one, which is the case for Julia thanks to PyCall. This is what I usually do when I go from Python -> Julia
:
- Create a script/workflow which you want to port to Julia, this can be something easy like calling a function, or more complex, like full analysis chain. Smaller steps are easier though.
- Write unit tests and/or high level tests in Julia to have an automated way of testing if the code does what it should. If you have a test suite in the Python project, you can start converting those first!
- Start to rip the code apart on the Julia side by expanding it and replacing the Python calls with Julia functions. You have the test suite on your side to make sure you have not changed the logic.
- Do not care much about how “Julian” your code is at this stage, just “make it work”.
- If there is still a Python call in the code: goto 3
- Remove
using PyCall
- Now you have a full conversion, time to refactor the code and make it more Julian.
I know, it’s a quite rough plan, but this has worked very well for many projects I have converted in the past. Again, thanks to PyCall
, the transition process is extremely smooth.