Approaching closures in unmanaged languages: a comparison between C++, Rust, and Swift
Approaching closures in unmanaged languages: a comparison between C++, Rust, and Swift
Luiz Romário Rios,Roberto Ierusalimschy
TLDR
This work explores and compares lambdas in C++, Rust, and Swift, and assess some properties of lambdas in the languages, namely: safety features, safe by default, safety guarantees, verbosity, type flexibility, and memory overhead.
Abstract
When using lambdas in managed languages, the programmer does not need to concern themselves with the disposal of the closure; in contrast, unmanaged languages that implement lambdas need mechanisms to make the closures be disposed safely at the right time. Through examples, we explore and compare the following languages: C++, Rust, and Swift. For each language, we implement examples of the usage of lambdas in increasing complexity, analyzing how they work while showcasing the implementations. After presenting the implementations, we contrast the languages regarding memory safety and typing. Finally, from those experiments, we assess some properties of lambdas in the languages and summarize them in a table, namely: safety features, safe by default, safety guarantees, verbosity, type flexibility, and memory overhead.
