#rust
3 posts

Rust Lang in a nutshell

StackOverflow's developer surveys have shows Rust to be the most loved language in the last couple of years. Infact, Deno is written in Rust!
Read more

Rust Lang in a nutshell

StackOverflow's developer surveys have shows Rust to be the most loved language in the last couple of years. Infact, Deno is written in Rust! Here's why:

  • Rust is a statically typed but intelligent enough to decipher types of variables where they aren't explicitly typed.

  • Immutable variables by default. This ensures that data cannot be changed by functions unless you specially mark the variable as such.

  • Ownership and borrowing of variables is the most important concept in Rust. It's also what leads to a higher learning curve. Each value is "owned" by the variable that is destroyed when it goes out of scope.

  • When a new variable is assigned to the old one, the old reference is destroyed. Let's take a look at an example

    let s1 = "Hello world".to_string();
    let s2 = s1;
    

    s1 will cease to exist. The value of s1 gets transferred to s2.

  • A variable can also borrow the value from the owner. Borrowing is simply a pointer reference to the original data. Strict rules govern this act. For example, the borrower cannot outlive the owner in scope.

  • While this concept is a little weird, it prevents null pointer exceptions, dangling pointers and buffer overflows.

Given it's type safety and emphasis on data security, I think Rust will be the language to look out for in the next 5 years, or till another language is invented to take it's place.

Full Post here, 20 mins read

Rust performance pitfalls

Rust compiles in debug mode by default. It results in faster compilations, but does next to no optimizations, and slows down the code. It uses unbuffered File IO. So, when you write files, wrap them in a BufWriter/BufReader.
Read more

Rust performance pitfalls

  • Rust compiles in debug mode by default. It results in faster compilations, but does next to no optimizations, and slows down the code.
  • It uses unbuffered File IO. So, when you write files, wrap them in a BufWriter/BufReader.
  • Read::lines() iterator is easy to use, but it allocates a String for each line. Manually allocate and reuse a String to reduce memory churn to gain a bit of performance.
  • In simple cases, use an iterator instead of an index loop.
  • Avoid needles collect() and allocations.

Full post here, 7 mins read

Why Go and not Rust?

Some of Go’s characteristics make it a fantastic fit for developing enterprise software. Enterprise software development is all about scale & dealing with complexity and Go is all about suppressing complexity at scale.
Read more

Why Go and not Rust?

Full original post here

Though this post compares Go & Rust, the underlying points succinctly explain how some of Go’s characteristics make it a fantastic fit for developing enterprise software. Enterprise software projects take time to build & tend to become large and complex. Many people (sometimes whole teams) change leaving behind a lot of code written with very varying levels of quality. Multiple teams working in parallel produce redundant code. The domain shifts over time, inevitably invalidating older assumptions and consequently causing abstractions to leak. Enterprise software development is all about scale & dealing with complexity and Go is all about suppressing complexity at scale. Here are a few Go traits that help tame the beast of enterprise software development:

  • Its concurrency model makes it a good fit for server-side applications that must primarily handle multiple independent requests.
  • Great support for HTTP & related protocols.
  • Great tooling to diagnose concurrency and performance problems.
  • Cross-compilation makes deployment on any platform easy.
  • It offers a limited set of features built-in the language making it easy to learn. Go forces people to “do more with less” which ensure that Go projects remain understandable even when they scale tremendously.
  • Go enforces a single, universal style via go fmt.
  • There are only two levels of visibility for variables, and the only concurrency model is CSP. It’s way harder to fall into incomprehensible pitfalls when writing in Go than in other languages.

Read the full post here and I am sure you will love the author’s pragmatic conclusion as much as I did:

“Let’s avoid tying our identity to a single language and embrace practicality first and foremost.”

9 mins read