Pixelo789

I don't like Rust

TL;DR: preference.

Note: I come from an interpreted language background (the first programming language I learned was Python).

Rust is a popular compiled programming language. I've heard about it in other places, and have tried programming in it, but couldn't really understand it well.

Issues/complaints I have with Rust

Syntax

This might not be so much an issue with Rust itself, but with compiled languages in general.

Because of the way Rust is designed, I need to add many annotations and otherwise unnecessary details.

As an example, let's imagine a function that requires the input values to be immutable, but you want to be able to change those values. An implementation in, say, Lua, wouldn't have to do anything weird because immutable variables don't exist in Lua. I also don't need any reference annotations; the Lua virtual machine handles all of that with garbage collection. An implementation in Rust, however, requires random "Cell" objects and reference annotations.

A real-life use case of this is on of the example applications in the GUI development with Rust and GTK 4 book. The "GObject Subclassing" example has 68 source lines of code (SLoC), while the following Lua implementation[1] has 34:

-- SPDX-License-Identifer: Unlicense

local LuaGObject = require "LuaGObject"
local Gtk = LuaGObject.require("Gtk")

local function new_application_window(window)
	local button_counter = 0

	local button = Gtk.Button {
		margin_top = 12,
		margin_bottom = 12,
		margin_start = 12,
		margin_end = 12,
		label = "0"
	}
	function button:on_clicked()
		button_counter = button_counter + 1
		button:set_label(button_counter)
	end
	window:set_child(button)
end

local app = Gtk.Application {
	application_id = "org.gtk_rs.GObjectSubclassing2"
}

function app:on_activate()
	if app.active_window then
		app.active_window:present()
	end
end

function app:on_startup()
	local window = Gtk.ApplicationWindow {
		application = app,
		title = "My GTK App"
	}
	new_application_window(window)
	window:present()
end

app:run()

Gtk Rust Book

GObject Subclassing example

Since the Lua implementation uses less lines than the Rust implementation, the Lua implementation is also clearer. Since there is no need to worry about technically superfluous details, both me, the programmer, and you, the person reading the program, are able to understand it better. Yes, there's some syntactical sugar such as the "end" when defining functions and the lack of a "+=" operator, but it's better than:

I prefer learning by doing; I learned Python and Lua by writing Python and Lua code, respectively. Rust's syntax and design, however, makes it difficult for me to learn through doing; it's off-putting.

Implementation

There is only one real implementation of Rust: the official one, leading to a monoculture. This implementation is also incredibly large; Lua's implementation(s) is(/are) definitely much smaller.

This implementation (the only one) is written in Rust (i.e. self-hosting). While self-hosted implementations of programming languages have some benefits, it also introduces a pain for bootstrapping (compiling the compiler from scratch). Since the compiler isn't easily compiled with a C compiler, for example, you typically have to use precompiled versions of the compiler with origins that aren't easily reproducible.

Official Rust implementation

Wikipedia page on self-hosting compilers

Community

It seems like, according to the Rust community, everything written in a language that doesn't have built-in memory-safety is inherently unsafe and therefore should be ported to or have a "safe" wrapper for Rust.

In case it isn't clear: it is possible to write fully safe code in C (or another language without memory-safety), and it is possible to write unsafe code in Rust. Just because a program is written in C doesn't mean it has been infected with a virus and will be plagued by stack overflows, and just because a program is written in Rust doesn't mean it is perfectly fine and will never have a memory error ever.

The proper way to reduce memory errors (and bugs in general) is to write smaller programs, not slapping a borrow checker on the problem and calling it a day. A smaller program means more intimate understanding with how it works, and less errors.

I don't fully understand Rust (because it's too much of a behemoth for me to learn), but it seems like that from an outsider's perspective.

Conclusion

I apologise if this post came off as more of a rant; I'm trying to post more and this was written in about 3 hours total.

Overall, Rust is too complex for me to learn, and it makes some choices which I very much don't like. I'm sticking to Lua.

[1]: While this Lua implementation doesn't use subclasses (classes don't exist in Lua), my point is that the same thing in Rust takes more SLOC than in other languages.