Advice on starting a big project correctly

I would like some general advice right at the start of a journey in swift. I have a python program which manipulates arrays of points generated from STL files in various ways and outputs Gcode for 3d printing while also using the blender API to show the likely result. The program uses TKinter, Matplotlib, numpy, scipy,shapely and that sort of thing and it is big (for me anyway about 10k lines of code).
However it is slow even on a fast laptop and the hope was to move languages, dump blender as the output and exploit the fact that the users of the program both have apple silicone MacBooks.

With all that in mind the plan was:
1 Learn swift (in progress) - to a python programmer swift is actually a tough climb (so far).
2 use swift's own app building capabilities to build a Mac OS app to replace the tKinter bit.
3 try to understand how to use swift and perhaps C++ libraries to replace all the math /array manipulation and make it go faster
4 try to understand how to use 3d rendering in some kind of swift package to do the task blender was doing (essentially turning a series of curves defined as line segments into a display of a tube that follows the curve (ie showing what a 3dprinter would extrude). With luck getting this to go fast enough not to have to defer the whole plotting activity until the end but to see it dynamically as variables are changed by the user.

Is this a mad plan?
what bits of swift and the UI should I focus on - I have no interest in running this on an iPhone/watch/iPad... and no commercial ambitions.
any good resources?

CD

I wouldn't say mad, but ambitious perhaps. Rewriting a non-trivial program - especially one with quite a few 3rd party dependencies - is quite non-trivial in itself.

Know that Swift & Python can interoperate pretty nicely¹, so you should at least consider leveraging that to do a gradual transition, incrementally replacing your Python code with Swift if & where appropriate. You might find you don't actually need to rewrite all of your Python, just the performance-sensitive bits (and perhaps the GUI bits, as you'll probably get a better result from Apple's native GUI frameworks than Python's options).


¹ There's lots of tutorials around on how to do that, and I'm not sure which is best, but this one seems decent at a glance.

2 Likes

Sounds overly ambitious, I'd pick something much much easier for the first project.

With this one, I'd rewrite UI from scratch, first running with some mock data. Then change the mock data to real data taking bits and pieces from Python / C++. Then if needed convert some of the Python/C++ to Swift (not necessary for those parts that are fast already).

I mean, if you're interested and invested, I'm sure you can figure it out. I agree with the first poster - try creating the UI with dummy data first, then incorporate the APIs.

I largely learned Swift/SwiftUI (Swift's current UI framework) from Kodeco.com, which has a lot of great tutorials, but requires you to pay for a membership to the site. I might suggest going through a tutorial to create a Mac app first, then trying to apply what you learned to your app. If you can only find iPhone tutorials, don't worry - SwiftUI is largely the same across the different devices - there are a few extra components that are available for larger screens, that's all.

Thanks so much everyone.
I am interested and invested as it happens and I learn much better when I have a goal in mind.
I am getting on with learning Swift which is weird for a Python user.
I think that the UI bit of Swift will speed things up a fair but but I have also come across the Accelerate module/framework/thingie and since two super slow bits of my code involve a very large number of simple linear algebra operations on a lot independent points Accelerate looks like being really worth the investment.

It's worth noting that numpy is capable of using Accelerate under the hood. Might be worth checking if your copy of it is set up to do that before embarking on rewrites :slight_smile:

2 Likes