I started learning Rust.
In fact, I should say I resumed learning Rust since since I commenced following "The Rust Programming Language" book (affectionately called 'The Book') a while ago.
This time, I follow a course on Udemy: The Rust Programming Language. I find that it offers the essentials while leaving it to me to go deeper into details when I need it. A very easy to follow course, I've already parsed 30% of it.
Java and Rust?
I work with Java, I love the ecosystem and I think it is a good place to get into and stay there. So, why Rust?
Well, besides the obvious that a software engineer should know more than one programming language, the benefit I wish to derive from this effort is to grow as a professional when it comes to concurrency.
Rust has this excellent feature called ownership. It is a simple yet brilliant scheme that addresses the problem of concurrent access and finding a disciplined way to do it.
Java solves the problem of concurrent access via mutexes, monitors and the like. Nonetheless, the burden of corectness is on the programmer: the compiler performs no check in this respect because the language itself is almost completely oblivious to concurrency (the well-known synchronized and volatile help but don't prevent).Rust takes a different approach.
Instead of allowing multiple agents to modify concurrently and then introduce mechanisms for exclusion that the programmer must employ in the hope that they will get it right, Rust simply disallows multiple agents to modify the same piece of data into the same time.
How does it do it? By keeping track which agent owns that piece of data at any point in time and enforcing that only the owner may change it.
All great, but the brilliant part is not this. The brilliant part is that ownership can be inferred and tracked at compile time.
In other words, just as I can't mess up the field addresses in a type-safe language like Java or C#, I cannot mess up concurrent access in Rust - and both aspects are taken care of even before I run the program for the first time.
Still, Java and Rust?
Given that I will not use Rust professionally any time soon, what's in it for me as a technologist active in the JVM ecosystem?
Well, I believe that knowing Rust has the effect of a better awareness of concurrency and, arguably, of a better personal discipline when it comes to software where concurrency is unavoidable, the risk of error is non-neglijible and the cost of a mistake is high.
Whether the intent will deliver as envisioned, it is to be seen. Meanwhile I am having lots of fun with the language.
No comments:
Post a Comment