News for hackers. Stuff that matters.
Re:Speedy Desktop Apps with GTK and Rust by pjmlp on Saturday July 06, 2019 @01:33PM (#20370717)
Agreed, I went through the same pain when I ported by dummy Gtkmm from an old article into Gtk-rs, Rc<RefCell<T>> everywhere.

This is such a pain that even Gtk-rs samples have macros to work around cloning widget state into callbacks.

From my point of view language ergonomics still need to improve for Rust to actually be a candidate for GUI development, versus what the GC based languages (RC and tracing GC) offer out of the box with their UI kits.

Unless one envisions it just to take C++'s role of visualization layer and integration with graphics drivers.

Re:Speedy Desktop Apps with GTK and Rust by barrkel on Saturday July 06, 2019 @06:13PM (#20372335)
One way to handle GUI componentry is to separate out the notions of ownership, parentage and reference.

Ownership defines who frees who. Parentage defines control nesting. References should to be handled via an indirection (e.g. names) and a protocol so that referees get notified when referents die. The indirection means that components get wired up in a late bound fashion; and the late binding means the gubbins for a protocol can be in place by then.

This stuff was figured out reasonably well with Delphi's VCL.

Re:Speedy Desktop Apps with GTK and Rust by pjmlp on Sunday July 07, 2019 @12:57AM (#20373629)
I guess the advantage here is that Delphi and C++ Builder don't have a borrow checker.

Even simple stuff like what Apple has demoed with SwiftUI designer can be a challenge, as you cannot just drag stuff around without changing the ownership semantics.

Naturally Swift has the advantage that Rc<RefCell<T>> is implicit, so it isn't as if the cost is magical gone.

However having to deal with it explicitly is a hard sell for anyone used to the comfort of GUI tooling.

So I imagine Rust is an easier sell for doing the low level stuff of a GUI engine, with what 90% of the devs using some managed language on top.

Basically what is happening to C++ on current desktop and mobile OSes, although for different reasons.

Or what is being done to Firefox actually.

Re:Speedy Desktop Apps with GTK and Rust by Matthias247 on Sunday July 07, 2019 @02:16PM (#20376674)
I tried event-driven programming with Rust 4 years ago and came to the same conclusion. It just isn't a good fit for the language. Rust works best when there is a stack and clear ownership semantics. Any kind of callbacks cause a certain amount of pain due to the need for unergonomic wrapper types.

Since then it got better libraries which reduce lots of the verbosity (e.g. gtk-rs), which is great. But the language itself probably won't change too much to better accommodate that use-case, since what things things painful here are the core features that prevent issues elsewhere.

I think we have to accept the fact that for different kinds of problems different programing languages are preferable instead of trying to find a single solution for all problems.

For UIs I think a naturally garbage-collected or refcounted language with reasonable support for dynamic dispatch is a lot easier to work with. In addition to that a restriction towards a single thread or even an inbuilt event loop can avoid bugs, improve interoperability between libraries, and reduce the amount of boilerplate and application-level design decisions even further.

If we take those properties we get the most common languages for GUI apps: Javascript/Dart which have single-threaded runtimes, and C#/Java/Kotlin/Swift as general-purpose languages which are more powerful but require an eventloop on application/library/framework level.

Those properties actually also expand to other very stateful and very concurrent applications. E.g. stateful network servers (something like Redis or a websocket server) have similar implementation challenges, and therefore are currently not very straightforward to write in Rust either (compared to e.g. in node.js).

Re:Speedy Desktop Apps with GTK and Rust by ptx on Saturday July 06, 2019 @04:05PM (#20371597)
In SWT, even though Java is garbage-collected, resources must be explicitly disposed[1]. Often they are bound to the lifetime of a parent object and disposed when that parent is disposed.

This seems to work OK in SWT, so what's the problem in GTK/Rust? Are there some particular categories of objects that don't fit into that hierarchical model and need to be handled with a GC?

(Those objects would presumably be regular Java objects in an SWT app and handled by Java's GC.)

[1] https://www.eclipse.org/articles/swt-design-2/swt-design-2.h...

Re:Speedy Desktop Apps with GTK and Rust by pjmlp on Saturday July 06, 2019 @04:56PM (#20371905)
The problem is called borrow checker, and that while the Rust team already has done lots of improvements with NLL, the use of widget data in callbacks remains a pain point.

"Appendix: What the proposal won’t fix"

http://smallcultfollowing.com/babysteps/blog/2017/07/11/non-...

So one could say, it is a case of holding it wrong, and a Rust UI toolkit needs to be written from scratch. Which might be ok, but it does require some support for market adoption.

Having said this, Gtk-rs now has some help in the form of relm, exactly to overcome this issue.

https://github.com/antoyo/relm