The MoonGuard team chose Golang instead of Rust for their Krater desktop application because memory management, type safety, and ORM support are easier in Golang.
Some challenges faced when using Rust and Tauri include:
-
Difficulty in understanding Rust’s ownership and borrowing rules,
-
Its strict type safety sometimes limits development speed,
-
Difficulty in finding a suitable ORM for SQLite,
-
And testing is very complex.
When the project was about 65% complete, the team was still working hard to finish the remaining features that required Rust code. However, migrating to Golang using Wails allowed them to port almost all progress over a weekend.
Golang’s garbage collection, Goroutines for concurrency, simpler static types, availability of GORM ORM, and a larger ecosystem due to its age make it more suitable for the project than Rust.
The Krater desktop application is a cross-platform tool for debugging Laravel applications locally. Krater was born out of our need as developers for a custom tool that provides a better (local) debugging experience for Laravel applications or PHP projects.
The goals of Krater are:
-
Data Persistence: We want data to persist between programming sessions and even store data from multiple projects.
-
Performance: We want Krater to be very fast and avoid memory crashes when processing data.
-
Disk Usage: Krater should be lightweight and occupy minimal disk space. Currently, it is about 18 MB in size.
-
Memory Usage: We do not want Krater to hang when receiving large amounts of data from Laravel or when displaying multiple records in a window.
Within the team, we have experience using Electron, but we knew beforehand that it would not provide the convenience we sought when developing Krater. We realized that using Electron would prevent us from achieving Krater’s performance, disk usage, and memory goals. Therefore, Electron was excluded from the start.
From the available options, we chose Wails and Tauri for the following reasons:
-
Based on web technologies.
-
Frontend agnostic (allowing us to use React, Vue, Svelte, etc.).
-
They meet Krater’s performance, persistence, and efficiency goals.
After testing both technologies, we found them both effective and ultimately decided on Tauri because it has better support, maintenance, and contributions on GitHub.
None of us had experience with Rust, and this was our first exposure to Tauri. As a team, we accepted the challenge of learning Rust and Tauri to develop the application.
The development of Krater progressed slowly in the first few months, but by the third month, we started to find a better rhythm and understanding of implementing features in the language. Over time, we increased our pace until we reached a crossroads.
Problems and challenges encountered using Rust:
-
Understanding ownership transfer and management is one of the most confusing and complex aspects of Rust. It is crucial to consider the execution flow of the program and manage mutable and immutable variables in memory to avoid getting lost in the code. Mastering this, along with using threads, was one of the most time-consuming tasks for the team.
-
Rust is a language with strong type safety, acting as a barrier against unknown format data and ensuring code safety at compile time. This strict functionality can sometimes feel uncomfortable when proposing solutions in code. We often hear the advice to start with simple, flat code and then build it better. This aspect sometimes limits our development and consumes time, making us question whether Krater as an application needs this level of safety constraints.
-
In this project, we used SQLite as our database, and finding a good ORM was a daunting task. We tried various libraries, but none satisfied us. The most stable option at the time was Diesel; however, it did not meet our needs, and we also believed the documentation could be improved.
Comparison between Rust and Go:
-
Golang and Rust handle memory differently. Golang uses automatic garbage collection to mitigate issues related to memory leaks. Its management is done at runtime, which may incur some additional costs. However, Golang provides Goroutines, allowing functions to run as threads, making concurrency easier.
-
Both Golang and Rust offer type safety, but Golang is statically typed and uses a garbage collector for memory management (as mentioned). Compared to Rust, Golang’s type system is simpler.
-
Go’s GORM is a very good ORM library. We use it to define tables, run migrations, delete records, and perform many other operations. It has comprehensive documentation with numerous examples.
-
Golang is several years older than Rust, reflected in the size and maturity of its community, as well as the breadth and depth of library documentation and resources. Along the way, we found Wails’ documentation helpful, along with some books as learning materials for the team.
-
Writing unit tests in Golang is simpler and easier. Golang provides built-in support for unit testing through packages. We were also able to validate and create mock behaviors for some objects in the code.
After several months of development, we successfully developed Krater 100% and reached the first stable version. We are very satisfied with our experience using these two frameworks and what we gained in developing this product this year.
Comments from netizens:
ORMs are useful, but they also have limitations. ORMs only become apparent when the language lacks a native query structure.
ORMs are worth it for including and encapsulating nested objects. SQL support for associations in result sets still needs improvement. Direct SQL remains important.
I have always believed that the database is the source of truth, not the ORM data model.
Understanding SQL is sometimes a prerequisite for using certain advanced features of ORM.
For students interested in programming and the workplace, feel free to contact me via WeChat:golang404, and I will add you to the “Programmer Group Chat”.
🔥Tiger’s Private Collection Hot Recommendations🔥
Tiger, as an old coder, has compiled the most comprehensive“GO Backend Development Resource Collection”.
The resources include“IDEA Video Tutorial”, “Most Comprehensive GO Interview Question Bank”, “Most Comprehensive Project Practical Source Code and Videos”, and “Graduation Design System Source Code”, totaling up to650GB. Allfree to receive! Fully meets the learning needs of programmers at all stages!