---
title: "Rust is pretty good (Short thoughts on Rust)"
date: 2024-04-09T21:31:01-04:00
topics: ['rust', 'Opinions', 'software development']
---

In my current position I've had to swap to full time Rust development.
After about 2 months of full time Rust development I think I'll likely be developing projects in Rust in the future instead of C++ when performance is important.
My reasons for this are primarily:

1. Just Works™ build system and crates.io makes drawing in libraries painless
2. Guaranteed memory safety is pretty nice
3. Syntax is much cleaner and succinct than C++, with lots of nice syntax sugar to sweeten the package
4. Easily integrable with C (and therefore C++ with some massaging)
5. Proc macros are pretty nice as well
6. Built-in test framework

I think that point 3 is potentially the biggest factor for me as the C++ modern syntax is not what I would consider clean, especially if you are trying to use a more functional programming style. 
A simple example highlighting the difference:

**C++**
```c++
vector<int> v(10,1);
std::transform(v.cbegin(), v.cend(), v.begin(), [](int value){ value + 1;})
```

**Rust**
```rust
let v = vec![1;10];
let v = v.map(|val| val + 1).collect()
```
**I think that speaks for itself...**(Although I prefer the C++ lambdas which don't auto capture)

I'm not sure that I consider myself a Rustacean though as some seemingly simple programming tasks can become huge mountains due to the borrow rules Rust enforces.
Once you learn the borrow rules and some of the tricks, the language itself ends up being very clean to write and easy to test.
I probably won't be writing C++ in the future unless I have a very specific/niche reason to. 
I recommend checking Rust out if you haven't yet, it may surprise you!


