From Ruby to Rust
Joshua M Loran
Posted on April 24, 2019
I’m more than half through a software engineering bootcamp. I can’t believe how much we’ve learned over the last 2 and half months, and how much information I’ve been able to cram in this melon. But, if you’re like me, you’re passionate about software engineering and thinking about what your next step might be in the engineering world. After learning Ruby, Ruby on Rails, Javascript, HTML, and CSS, I’m learning some of the limitations of these languages as well as their strengths.
Ruby is an intuitive, easily readable, and easily setup language. With Ruby on Rails, typing in a generate scaffold command sets up the start of a backend server that might take a day more to type out from scratch, but does in it a few seconds. Ruby has syntactical sugar on top of syntactical sugar to make typing out code pleasurable. Like wait…I don’t need parenthesis here or typing there, but how does ruby know…magic. Ruby is full of magical behind the scenes workings that just make programming easier and more intuitive than most other languages. This magic is part of what made Slant.co rank ruby 5th for beginning developers. Why not first? Because the magic of Ruby comes with several drawbacks.
Developers that start with Ruby, and only know Ruby, may not understand things like pointers, typing, and/or data structures. Also, since Ruby almost strictly functions as an object oriented language, Ruby only developers may not learn or understand many of the other programming paradigms. Ruby also has limitations of scale and resource consumption making working with larger projects far less efficient, case in point Twitter switching languages. So...
All this brought me to a question. What would be a good language to learn that would help solidify deeper concepts and make me a more useful and productive developer? I want to write efficient code that uses minimum resources. I want to have the power of C++ without the years long learning curve or the complexity of syntax. And, I wanted the enjoyability and ease of coding I get with Ruby. I’d heard about Rust from a few more experienced developers that were kind of pointing me towards it after I told them what I was looking for.
Rust is closer to C than Ruby. However, It has better memory safety and management. For example, pointers are not allowed to point to other pointers. On compile, the intermediate pointers are removed from the equation. Types are only mutable or immutable if you explicitly them to be. There is also no automated garbage collector. Instead, it uses RAII (Resource Acquisition Is Initializtion) which provides deterministic management of resources and at compile, prevents things like dangling pointers and other forms of undefined behavior. Also, the syntax and code structure force developers to write optimal code.
Because of its memory safety and resource efficiency, slant.co has ranked Rust as the #1 language to learn for backend developers, the #2 language for concurrency and meta programming. Rust also earned #1 as the best all around compiled language, as well as 2017’ and 2018’s most loved programming language on Stack Overflow’s developer survey.
Getting started with Rust is fairly easy and straight forward. You can read “The Book” online. The book will walk you through all the basics from Hello World, to building a CLI, and even a server setup. Going from any language, even magical Ruby, to Rust isn’t too difficult since a lot of the concepts are the same. You just get to learn to how to have more control over how things work. In ruby, you might make an object that looks something like:
In Rust, the same thing might look something like:
Rust has a large community to learn from and is well documented. So, as you dive deeper into the language there is ever more information and people to learn from.
Posted on April 24, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 29, 2024