Dabbling with rust

I have been dabbling with the rust programming language lately, it is quite refreshing compared to my work around high level programming langauges such as PHP, Ruby and JS. These are some of my thoughts on rust comnig from a high level programming language.

Memory management

In high level programming languages rarely do you worry about memory management, I’m not talking about direct memory manipulation as this is often not possible but rather the life time of your variables and objects as they are usually freed by the garbage collector, on the odd occasion you may have a run longer program which uses an ever increasing amount of memory or one that uses large amounts of data.

From a rust perspective you need to understand the difference between a stack allocated variable and a heap allocated variable and although I have learned this from university rarely did I think about it when programming perhaps this make’s me a bad programmer but generally I left it to the programming language to determine the best location of my variable or object.

Ownership

Again when programming I didn’t think about the ownership of an object, of course I was aware that by passing a variable to a function that it may manipulate that, but I did not think about whether it should hold on to that reference and make changes in future invokations unless it was expected. I think this could be a potential issue if you’re not anticipating it e.g. Doctrine’s managed objects.

In rust you have to think careful about who owns what, so as to avoid a dangling pointers and instead it introduces a trivial concept of ownership where as only one context may own the variable at any given time and even then the ownership may have restrictions e.g. immutability. Given this I think it allows you to reason about the system a lot easier give

Locks

Options and results