From Rust to Swift

As the Rust programming language continues to spread through the open source community, I find myself wanting to leave it. I haven’t touched it since the pandemic. The borrow checker is just so annoying to use. Like, the compiler could hit on you upside the head for the most benign things. It’s so frustrating. xD I’ve yearned for something that was just as safe without sacrificing damn near everything. My first attempt was with Zig and, as much I really liked it, the language still has some teething issues.

Now, I’ve been keeping track of Swift on and off for a long time. Roughly since it’s debut in 2014. Helps that I’m a Mac user. Despite suffering similar teething problems as Zig, it evolved rapidly and matured a lot since 5.0. I decided to give it another shot when I was setting up my Linux laptop. The RAM is very small by today’s standards so putting something like Rust’s complicated build system wasn’t much of an option. So I created a series of command line applications after I discovered that’s what “tool” option meant. My first attempt was creating a simple program that generates a desktop entry for Linux. It was quite simple to make. Like, the whole program is roughly a 100 lines of code. (Although, if you focus on the actual logic portion, it’s probably way tiny.) And although I haven’t properly tested it on a distro yet, the dry runs are working flawlessly.

I have a number of other tools written in not only Rust but C# that could do with a proper rewrite. The most complex are written in C# while the simpler ones are in Rust. My most simplistic is a D&D dice roller. I had planned to add support for modifiers but my issue with the borrowing checker forced me to abandon it. On the C# side, my tool used to used to streamlines building an EPUB using Pandoc is slightly more complex.

I decided to start simple and rewrote that dice roller. While it shares a roughly similar architecture as the original, there are some notable differences that make the two incompatible. Like instead of typing in any number using the --roll option, you can specify “d2” to “d100” as argument and add an additional --modifier option that you can type a number into. This new version functions more like an actual dice roller you’d use in D&D or any other tabletop game and less like random number generator dressed up as a one. Next up is allowing for multiple dice to be rolled so you can create different builds.

All that being said, Swift is turning out to be a joy to develop for and I may use it to create more tools in the future. Regardless of what some people may say, programming shouldn’t be a chore to do. I stuck with C# and tried out Zig preciously because it didn’t punish me for programming the way I was taught.

And don’t get me wrong, Rust is a great programming language. Once you get the hang of it, it is powerful tool to use like anything else. Rust has earned its spot to be adopted into the kernel and other Linux distros. The language was designed to handle loads like this. But it isn’t for me anymore.

Leave a Reply

Your email address will not be published. Required fields are marked *