Look Ferris is cute and was a hit with my kids when they saw him… quite in contrast to the Rust logo, that I’m too afraid to even show here.
Wow what a start huh? It’s not that bad but while I was learning Rust a bit of drama has occurred around the Rust foundation… enough of that though, let’s discuss the doings of codes.
Note: This is a bit of a brain dump based on my recent experience so let me know if you find any issues.
How did I end up migrating to Rust?
Not sure what I was looking for and I’m fairly certain I didn’t search “Middle age man yells about coding” but I ended up watching a few of the Primeagen’s videos (ok ok I binged this handsome mans videos alright) and while I had heard of Rust before I never really thought about using it, it’s for the crypto bros right? As the great youtube algo does, it lead me to other youtubers (links at the end) covering Rust that would lead me down the Rust rabbit hole.
While that seeded the idea of using Rust, what pushed me further unexpectedly ended up being a tiling window manager for Windows called Komorebi. Well it’s written in Rust so must be superior to the other ones out there (yes Windows has a tiling window manager and even has more than one, who knew?). It’s still a bit rough around the edges and being open source meant I could have a crack at fixing some bugs. So I started playing around with the code and while Rust is a bit of a different language, I got the hang of these small changes/debugging quicker than I expected. It did give me a feeling of what I’d be up for in building something in Rust, furthering my interest in finding a project to build.
After being woken up from an alert because of an issue with one of our tools that is (looks sheepishly) in PHP 😂, I started looking at options to fix the issue. Ok okay, there is a reason it’s in PHP and it evolved into what it is now, we’ve all been there. As a business supporting mostly PHP and C# software, C# was the obvious destination I had in mind and the tools we already made in it were still running years later without any issues (fact check required).
With an increasing allure to Rust, I realised I now had a good candidate project to work on. I came up with a simple CLI concept app to keep most of the PHP code still being used and get Rust to help with the areas where it struggled. This minimised the amount of coding required and kept the business logic still in PHP so it’s not being leaked into other systems.
I’ll admit, I thought some of Rust would be easier to learn but when you write something from scratch you have to structure things and make micro decisions on design, this is very different to just adding onto an existing system where a design or structure has already been established, like what I was doing with Komorebi.
Most of my issues were from my lack of experience, I’m certainly no “Tom” and being an average developer meant I spent a fair bit of time trying stupid things (a bit tedious in Rust tbh), asking chatGPT or even reading StackOverflow (a lot of stuff was out of date). I think the big shift mentally was the shift to expressions not statements, this changes how things flow compared to my existing code.
Once I got a bit of code working and understood the syntax better it did become much easier, by the end it felt more natural when changing the code and could obviously reference my existing code.
It is only a simple CLI application doing some HTTP calls and DB queries so nothing crazy, but I was surprised at how long it took me to get parts working making me question if Rust was the right choice. TBH I’m still not sure it is, while I have quite a bit of trust that the app will just run now, I’m concerned that if I don’t continue building in Rust when I need to change the app I’ll have no idea what I’m doing anymore.
I did learn a lot through the process though and I now love the option/result types. For these being around for so long I’m surprised they aren’t used more and I’m now using them where I can in my PHP code.
So the good points:
- No nulls
- Strong IDE integration (I used VSCode and moved over to CLion)
- Strictness, once it compiles it just runs* (don’t use expect next time please)
- Strong tooling and range of modules that should cover most users requirements
- Decent documentation (give me more examples please)
- Learning the borrow checker
- Macros hiding implementation, feels too much like magic
- Tutorials/Examples showing poor or no error handling
I did struggle at the start with error handling, this is because of how a lot of tutorials go through this, use different ways of handling result or the ? operator. Main lesson is don’t use expect or panic (unless you intend to), understand how to best handle different error types and where error handling is best to sit. Coming from try/catch it is a much better and safer system but again it is a bit of a mental shift in thinking about error flow.
Why not X language?
One of the other languages I was looking at was Go and to be honest it just didn’t appeal to me at the time and while I still want to try it for some web/api code to understand it more. It would have likely been a good (possibly even better) choice for this app so hopefully I get a chance to try it out soon.
I looked at Ocaml but it seemed the Windows support was not at the level of .NET, Rust, Go or others. This style of functional language though seems to give that strictness I was looking for and that is why I’ve started dabbling in F#. From my understanding it was inspired by Ocaml, it runs in the .net core framework so will work across platforms and I *think* both F# and .Net core are fully opensource for those with that requirement. I had locked in Rust by this stage and was already building, so as a comparison I’m looking at just re-creating the app in F# to see what the difference is and get a bit of exposure to another language and hopefully another way of thinking.
As already mentioned this is about learning, I don’t need or want to move all my code over to another language unless it makes sense to. And let’s be real, most client projects will never migrate to another language/ecosystem so I’ll be programming in PHP and C# for a long while still and hope I can bring some of that knowledge from other languages to my day to day. There is certainly value in making sure to choose languages that are being actively developed with a large community, I hope I never get into a Ruby situation with my choices of language or tooling and back in the day I had to jump ship away from Classic ASP, thank god that was an awful langauge looking back now.
This has been a good experience in changing the way I think about problems and how they can be solved, we don’t get paid for code, we get paid for providing solutions.
In the end I think it was a decent choice using Rust, it certainly wasn’t a bad one. We get a stable and solid app that is unlikely to cause any issues. I look forward to more coding in Rust and other languages, even if only to learn more, become better a better developer and share knowledge with my team.
I wouldn’t use it for client software just yet based on my own confidence level and I’m already thinking of other systems I could upgrade to Rust to get more experience.
Thanks for reading, I hope this helps someone in a similar situation, comment and share this post if you’ve enjoyed it.