-- Leo's gemini proxy

-- Connecting to bbs.geminispace.org:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini; charset=utf-8

Building native UI applications on Linux in the declarative/reactive way?


I like GTK+ visually. It's minimalistic and all applications look organically on one Gnome-based desktop.


But when I decided to write an application myself for my favorite OS (Elementary), I went into a stupor.


You can only write in Vala+GTK in HORRIBLE imperative style.


After a long time programming in [Lisp Racket] and [JS], I can't go back to this. I can't imagine programming without lambdas and stateless calculations.


I've been looking for a good GTK binding for Racket for a long time but haven't found one (at least one that has the functionality I need).



I looked towards Qt, but QML looks very raw right now.


(Looks like I'll have to write the GTK binding for Racket myself.)


In general, discussion: Linux UI coding in declarative/reactive paradigm.


#coding #declarative #linux

🚀 ostov

2023-06-01 · 1 year ago


8 Comments ↓


🦀 jeang3nie · 2023-06-01 at 20:23:

I've experimented with Gtk+ in multiple languages. No matter how you dress it up, it's object oriented and if you fight against using it that way it just gets painful. Of the languages I've programed gtk+ applications in Vala is actually one of the nicer ones to work with, which is unsurprising since that was one of its prime use cases when they developed the language.


My best advice would be to separate the business logic from the interface as much as possible, and then you can keep the painful parts to a minimum.


🚀 ostov [OP] · 2023-06-02 at 07:20:

> No matter how you dress it up, it's object oriented and if you fight against using it that way it just gets painful.


I've seen a GTK binding on Racket that allows you to do everything without pain, but the problem is that the library is limited to primitive controls.


I think you can write a library that will draw the UI every time the data changes


> My best advice would be to separate the business logic from the interface as much as possible


It is possible more in detail? The bottom line is the construction of the interface, which I have is very dynamic (oriented to web content).


☕️ Morgan · 2023-06-02 at 08:28:

Not sure if it's at all what you're looking for, but as a Dart fan I have to mention Flutter ;) ... it's best known for mobile apps but does support desktop.


— Reactive User Interfaces


🚀 ostov [OP] · 2023-06-02 at 11:59:

> Flutter


Flutter looks weird on desktop, and I also looked at the example code for Counter on Flutter and it looks very verbose. On any JS framework, such a hello-world code takes a maximum of 10 lines of code.


🦀 jeang3nie · 2023-06-02 at 13:22:

> I've seen a GTK binding on Racket that allows you to do everything without pain, but the problem is that the library is limited to primitive controls.


Is this not painful? I've seen this in other languages as well, where you have a cool idea for how to make it (gtk+) easier to work with, but all of the code for the bindings is hand written and never finished.


As for separating business logic from interface code, I have a program which draws a guitar fretboard for you. There are controls for scale length, nut and bridge width, number of frets etc. Whenever you twiddle a control it collects the values and calls into a separate library, which returns an svg which is used to update the preview. So all of the interesting stuff happens in the library, where I don't have to care about Gtk+ at all.


Eva smallweb browser is similar. All of the network protocols are in the "Bucky" library code. But as the program gets more complex it's harder to keep the interface code to a minimum and there are definitely places where I'm not happy with it.


🚀 ostov [OP] · 2023-06-02 at 14:07:

To: @jeang3nie

The problem is in the interface code. I don't understand how to redraw the window interface when the given data changes.


This is critical for social applications where the interface is not static.


We usually have a State in which we store objects like blog posts. Then, when this state changes, it sends this state to the render function, where the interface is redrawn according to the state.


I'm a bit confused on how to organize this in GTK (Vala in particular).


🦀 jeang3nie · 2023-06-02 at 14:34:

@ostov I see. There is no overall render function in Gtk+ as it isn't an immediate mode gui, but retained mode. Each widget has it's own internal state, and you have to update whatever widgets that you wish to change. There are tradeoffs with any method of working and this way has plenty of tradeoffs.


☕️ Morgan · 2023-06-02 at 17:32:

Flutter works exactly as you describe; redraws are automatic from state. It's not JS, but then JS is not "native", although I was not clear if Flutter fits what you want there either. It can compile to binary code, it's native in that sense :) ... agreed about it not looking very desktop-like, I guess that may come later as desktop support is relatively recent.

-- Response ended

-- Page fetched on Sun May 19 11:41:26 2024