Switch from Delphi/Pascal to Julia

Dear Julia users,

I am using an optimization model which is written in Delphi/Pascal and is called from a Python-Skript. However, Delphi (in my opinion) is not a very user friendly language and I would like to switch to a more modern open-source language. Python is too slow for my use case, but as I understood Julia should be as fast as Delphi. As a Python-user I still want something that “feels like Python”, i.e. is interactive, well documented, easy to read and write and has packages for easy csv-Import etc. That’s why I ended up with Julia :slight_smile:

My question now is: How would you start transfering the Delphi-Code to Julia? The Code has approximately 20.000 lines split in multiple units and functions, so I won’t be able to translate it all at once. Can I call Julia-functions from Delphi and should start translating function-by-function? Or is it easyer the other way round - calling Delphi-functions from Julia and start translating the “surrounding” code? Or do you think it’s not worth the effort and I should stick with Delphi?

I’m fairly new both to Delphi and Julia and have no experience in combining two programming languages in one project yet.

Thanks for your responses :slight_smile:

Not exactly your question, but see Workflow for converting Python scripts - #3 by tamasgal

2 Likes

I am as usual going to say something stupid here. It looks like this code has been given to you, or you have taken over a project?
Maybe take a step back and ask what this optimization model is supposed to do.
Maybe there is a clean and easy way to write a model like that in Julia, with an existing Julia package.
I do not want to sound like a smartass here. All I am saying is take a step back before launching into a code conversion exercise.
Keep the existing ode and use it to verify your new Julia code?

ps. Welcome to Julia!

5 Likes

Well, probably you won’t need more then 2000 LOC in Julia for the same task, but that requires to rethink what the model is supposed to do…

thank you already for you’re replies!

The code is part of a project that I joined. So on the one hand, it was given to me, on the other hand it is still used by other people in my group. The model is an energy system model - so basically the function that get’s optimized. For the optimizer itself I’m sure I find an existing Julia package.

The energy system model is still used in different projects by other people and sometimes its further developed there as well. So switching language either needs to be very fast - or I always need a working model during the convertion time. That’s why I thought about transfering it to Julia step by step instead of rewriting everything at once.

I’d be happy to reduce the code to 2000 LOC :smiley:

I was thinking about something like that. But do you know if there is something similar like PyCall to call Delphi from Julia? Can you do something like that with CCall?

We had an old reactor model in Delphi. Rewrote into Julia. Speed-up 100x and much more maintainable. The only downside is not being able to easily compile to a DLL, but there are workarounds.

You can create dlls with delphi that can be called from C, and if they can be called from C then they can also be called from Julia. Not much documentation on how to do it available.

Example for calling Delphi dlls from R:
https://snoweye.github.io/R_note/inc_menu/reference/dfu/delphi_dlls_for_R.htm

Just try to create a simple example and we can help you to fix any problems you encounter…

2 Likes