Notes about Merge Sort in Rust
While overall I find programming Rust extremely fun and rewarding. I wanted to write several notes about caveats (or paradigm shifts rather) when programming Rust in comparison to an interpreted language or tried language like C/++.
The following implementation is a fairly basic O(n log n) version of Merge sort that works on any length array with relatively good performance. Topology and other factors should come into play before using a sorting algorithm for certain use cases.
You always have to declare mutability of objects
While I consider this a good practice where you have complete control over mutability and immutability of your variables and functions. In the case of a sorting algorithm, you'll more often then not need a certain degree of mutability with a certain range of variables. You probably observed that I had to "clone" the vector in order to mutate it.
Slicing vectors require for loops
Typically in languages like Python you can mutate an array/vector with something like `array[start:stop]` where start is the first item and stop is the last item in the index. Unfortunately, if you observe the code in Rust. I need to iterate for loops in order to achieve this. Fortunately the for loop ranges can be notated with `start..stop` which is a very convenient iteration function.
No ++ just var = var + 1
Something which sort of irks me and could've easily been implemented into the standard library is ++ and -- increment and decrement variable syntax sugar. It's not a big deal but I still do have to write an extra. Anyway, this pretty much sums up my comments about Rust in comparison to something like C++. Hope you learned something!