Rust, On Second Thought

Programming Language selection is an Architectural concern, where Software Architecture is largely about deciding on solutions that have a high impact on the Return On Investment (ROI) and Total Cost of Ownership (TCO) of a software project, on issues that need to be correct early on, issues that are hard to change later.

I’ve been following the Rust Programming Language for a while now, where I was curious, but could not feel inspired to learn more. Programming since 1970, I have used more than my fair share of different programming languages, and increasingly, it takes more than a few new bells and whistles to get me interested.

Until now…

Rust for the impatient

Based on the article, A half-hour to learn Rust, I cannot recommend these presentations for everyone, but if you are an experience software developer, who has studied and used a lot of different programming languages, I can enthusiastically recommend checking out these resources. :thinking:

As a very seasoned computer scientist, I was quickly able to grok the essence of Rust. :partying_face:

Background

Rust is a multi-paradigm, high-level, general-purpose programming language. Rust emphasizes performance, type safety, and concurrency. Rust enforces memory safety—that is, that all references point to valid memory—without requiring the use of a garbage collector or reference counting present in other memory-safe languages. To simultaneously enforce memory safety and prevent concurrent data races, Rust’s “borrow checker” tracks the object lifetime of all references in a program during compilation. Rust is popular for systems programming but also offers high-level features including some functional programming constructs.

Wikipedia, 2023-03-04

Impressions

  1. Originally, I felt that Rust was just another C, C++ wannabe language like Go.
  2. Unlike, Go, Java, C#, etc., Rust does not use Garbage Collection for memory management, rather it uses borrowing to manage memory more efficiently.
    • However, I cannot say more effectively because the cognitive load to writing software in this style is higher than with garbage collection
    • Engineering is often the art of compromise, where software engineering is no different, often leading to software architecture concerns
    • While I understood this long ago, it was really not highlighted in these learning resources I am recommending
  3. Having used the Scala Programming Language since 2005, I was surprised at how many Scala features Rust had ‘borrowed’ (pun intended).
    • Tuples
    • Match statements
    • Match statements, If statements, code blocks, etc. all return a value
    • Data is immutable, by default
    • Good support for functional programming
    • The “_” character, used differently, but similar to Scala
    • Excellent type inference, leading to less boilerplate
    • Type deconstruction
    • etc.
    • But, Rust seems to avoid some of the most controversial, and dangerous features of Scala, such as implicit
      • Indeed, Scala has many controversial and dangerous features, that are overly abused by ‘clever’ software developers
  4. Rust, I am told, has excellent compiler diagnostics, leading to a higher quality developer experience.
  5. Rust is a System Programming Language and indeed, parts of Linux are being implemented in Rust, in addition to C and C++.
  6. Rust is being used in WebAssembly

Unlike Java, .NET, etc, Rust generally compiles to native code, not relying on a Virtual Machine. However, used in conjunction with WebAssembly, we can think of WebAssembly as the Virtual Machine.

With improvements in the Java Native Interface, such as Project Panama, if you really need to focus on efficiencies that Java and the JVM cannot provide, you can call Rust code from Java.

Applications

While I have yet to use Rust in practice, I can imaging some great applications for Rust.

Safety and Security

Rust’s programming model goes a long way to improved the safety and security of code.

Micro Service

If you need to develop a very high performance cloud service, that does really intense computation, requiring low latency, Rust could be a good choice.

In particular, without Garbage Collection, the uncertainty of GC Pauses can be eliminated.

For example, if you are doing Fraud Detection, where you don’t want to keep the end user waiting too long to be verified, Rust could be a useful context to develop predictable, low-latency code in.

Fearless Concurrency

Fearless Concurrency describes Rust’s concurrency model, where concurrency is one way to increase throughput and decrease latency. In applications such as Fraud Detection, this is a valuable mechanism as often potential fraud signals can be explored in parallel.

However, not being an expert on Rust, yet, I cannot offer too many opinions on the quality of Rust Concurrency. I have seen both claims that Rust is slower than Go, and that Rust is faster than Go.

Full Stack

Given you can now write browser code in Rust, that gets compiled to WebAssembly, your Rust code can run in a WebBrowser.

Given that WebAssembly is evolving into a containerized system, the plan is for us being able to write portable Rust code that can be deployed in the Back End, as a service, or the Front End, as a Web Client, or in-between, on the edges…

For software teams that would rather not be polyglot, Rust could be a useful context to write full-stack code in a single programming language; am important software architecture concern.

1 Like