Hi, I have existing C/C++ code. Developed on Linux some years ago. Ported to Windows. It's not-UI software.
Given the push in the industry for memory-safe languages and interest in options other than C and C++ in general, I am exploring using Swift. I avoid language with heavy runtimes and GC (JVM, .NET, Go) because I am interested in performance (and determinism when needed).
I am also interested is going back to Linux. Even though my current software is non-GUI, I may wish to use Swift for GUI software e.g. on Linux or Windows.
I also like what I am discovering so far that Swift has good interop with C/C++! That's great!
I see Microsoft supporting Rust but not Swift (and I can only imagine the politics behind that) so I'm not expecting great Swift support on the Microsoft platform. I noticed that JetBrains apparently no longer supports Swift plugin but they do support Rust and .NET (and again I can't help but smell some platform politics here).
Is transitioning to Swift from C/C++ recommended? I am interested in Linux so is that also a recommended platform. With Swift originating from Apple (if I'm not mistaken) does that mean that other platforms are less-supported? (E.g. Objective-C did not have high visibility on Linux or Windows.)
Hi, first of all it‘s very appreciated that you consider Swift as your future safe language for your projects.
I can recommend watching this talk I recently discovered, speaking exactly about Swift as a C++ successor and the interop topic. It‘s 1 year old now, but still mostly up-to-date.
In my experience Swift does not have the best performance of all languages when following the safe Swift approach but it‘s acceptable for me and you can get far with optimizations. You can get pretty close to C when going the unsafe route though, on the other hand that limits the advantage of Swift.
Linux support got really good the past few years and Swift is now perfectly usable for Non-GUI applications. I cannot speak much of Windows support myself but from what I‘ve read on the forums it‘s pretty fine as well. While initiated by Apple there have been great efforts to get Swift more independent and fit as a general-use language.
UI support is more limited on Windows and Linux, There are (mostly due to the great C interop) some community projects bringing UI support to these platforms but I don’t know about the progress/usability there.
If you want a cross-platform UI library then you might like SwiftCrossUI, my declarative UI framework heavily inspired by SwiftUI. My recommendation is not biased at all
On Linux it uses Gtk by default, on Windows it uses WinUI by default, and on macOS it uses AppKit by default. You can override the default backend used because some backends (e.g. GtkBackend) support multiple platforms. There’s also experimental and incomplete support for using Qt as a backend.
I’m currently working towards finishing off a new layout system that provides much more layout consistency across the various backends while adapting to the differing default styles and padding etc of the various backends. The layout system is working for AppKitBackend and GtkBackend, but I haven’t updated WinUIBackend for it yet.
There's an amazing series of blog posts named Swift for C++ Practitioners I think it's a 10-part series, starting here. (And I wish similar articles existed for all possible pairs of languages )