Hackgregator rewritten in Rust

Some years ago i decided to write an application applicable to a GNOME phone because i really like to read Technews when i commute or have to wait somewhere. Typically i use a Android based phone for that but nowadays there is a PinePhone or the Librem 5 which can be based on GNOME architecture.

Of course it is possible to just open up the site on a browser but i wanted to try to make an application for the desktop. The technology to do something like this is quite interesting as it is necessary to interact with an REST API.

REST

Unfortunately the official REST API is not ideal. The idea is that every element is an item. Every comment, story or polls all are items and have to be fetched from the same endpoint. As every item can have multiple children items you have to swing along the trees to fetch all items you want to show.

Let me illustrate this: If you want to read the "Best Stories" site you call an endpoint best-stories.json which gives you a list of numbers. Afterwards you have to call item/<id>.json in order to get the complete data. After you fetched all data you can show this to the user. Similar things exists for comments. Your item contains only the top-level comment-numbers. Comments to comments have to be fetched separately. Writing such an application gets quite cumbersome as the bookkeeping can get fast out of hand.

Language

I wrote the initial application in C as this is the language i was most comfortable with and provided me the most type safety i though i needed. The biggest problem i encountered with C as language was the refactoring story. Its hard to fundamentally change implementation and restructure it to a better architecture. So your best bet is often times to design it upfront changeable and clean.

Rewrite

Fast forward 2 years and basically no maintenance work i decided to refresh my knowledge about Gtk-rs and write small bookkeeping tasks i encountered during my work on Hackgregator and 2 weeks later i have rewritten my old C based application in Rust. Kudos to the maintainers of Gtk-rs because i think the bindings are really great and its a joy to work with.

Summary of my rewrite

First and foremost i never planned to do this. Basically it just happened. I have some conclusion though:

  • Gtk4 is awesome. For sure there are still some areas which need some care but overall Gtk4 and the new ListViews are really nice and performant.
  • Libadwaita brings GNOME development to a new level. The new HIG is just nice and there are many batteries included that most of the design decision complement the development.
  • Rust is a nice (or nicer) language for static type lovers. I really love the missing NULL pointer and the Option and Result types as these let you exactly reason about the code to the correct point in time. Thanks to the borrow checker you won't add a XXX: doing this better but model it correct upfront in order to be able to compile.
0:00
/
Left is the new rewrite and right the old variant
Show Comments