NewsCrawler.org

How Rust changed the way one developer thinks about types and ownership

How Rust changed the way one developer thinks about types and ownership
Image: news.hada.io

The author has used Rust for over six years and has applied it professionally for more than four. The author says the language changed how they think about types, abstraction, ownership and performance. Sum types[1] and static dispatch[3] make it possible to model a domain without relying only on interfaces or runtime branching, and they make the cost of abstraction versus performance clearer.

Ownership rules push developers to separate data changes from data use, which lowers coupling. For cyclic structures, the author uses an arena[2], which stores nodes in an array and links them by index. The author built Xot after finding that the XML libraries they examined either were immutable or did not provide parent references.

Compile-time macros can generate repetitive code: serde creates serialization code from a derive attribute, and clap builds a command-line interface with help text from types and doc comments. The author admits that Rust is hard to learn, but says the range of what can be built with fewer resources has grown.

Read the original blog.startifact.comDiscussion on GeekNews

Discussion

Hacker News commenters mostly recommend learning languages from different families, such as Lisp, Prolog or Verilog, and one suggests solving the Advent of Code tasks in 12 different languages. Some praise Rust for forcing developers to decide how to handle failure instead of relying on remembering to check for NULL. One commenter criticizes Rust enums for combining the tag and the data, and contrasts this with Zig, which keeps them separate.

Sources

Published: First seen: Читать по-русски

Open as a page