How Rust Can be A Good Thing

20160820_135602_richtonehdrLast September I saw this article about a programming language I hadn’t heard about before. That language was Rust. At the time, I played around with it a tiny bit but saw no real compelling reason for me to invest the time into learning another language. Then, earlier this week I saw this article on arXiv, and decided to give Rust another look.

I started by opening a terminal window, and running a simple command

$ sudo dnf install rust

and within a few seconds I was ready to write some code with Rust. I went through the usual “Hello, World!” intro and again started asking myself whether it was really worth learning another language. After all, I already know C++ which can produce quite fast programs, and I know Python which can be useful for certain quick things, so why invest the many hours necessary to become proficient enough with Rust to actually make it my “daily driver” for writing code?

Nevertheless, I decided to continue down the “Getting Started” chapter of the Rust language documentation, and that’s when I found my reason: Cargo. Cargo is a wonderful tool that makes keeping your work organized a breeze. From the command line simply type

$ cargo new project_name --bin

and it automatically makes a directory structure for you and creates the configuration file you’ll need. This forces you to think about your work as a project, which encourages you to separate out your pieces of code into modular bits. Additionally, it makes compilations and dependencies a breeze! Seriously, you just need to edit a file to say your code will depend on some library, or crate in the parlance of Rust, and when you compile it will automatically download and install the necessary components. This means that you could write your code, comprise the directory to archive, email it to someone and that person could just decompress, and compile with cargo.

No more tracking down dependencies! No more code breaking with newer library versions! Code sharing becomes a breeze!

(Just like a cheesy infomercial) But wait, there’s more!

When you create a project with Cargo, the configuration file has a version number in it by default, encouraging you to actually version your code (something that I essentially never do). This can help people who may want to use your code since they can make sure they are actually using the latest version, or that they are using the same version you did to produce the results in a particular paper. Of course, that assumes that you actually share the code you used for the paper (something that I think should be done more often).

At this point, I can’t say for sure that I will definitely be switching to using Rust, but I am impressed enough that I will be delving into it a bit deeper. If it turns out to have all the tools that I need, and the performance is as good/better than equivalent C++ code (as it seems it should be), then I will make the switch.

I encourage all of you to check it out for yourselves using the links above! Happy coding!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s