Ruby vs JavaScript Summary
In short, Ruby is an object oriented language typically used for server side development. JavaScript is also object oriented and typically used for client side applications. JavaScript is far more widely used than Ruby, although Ruby is still a strong language.
JavaScript is one of the number one languages on the web. If you’re developing something for the front-end, chances are you’re going to be making it in JavaScript. In fact, JavaScript is the most used language on Github at time of writing. Ruby is another general purpose programming language that is also in use on the web, especially its web framework, Ruby on Rails. How do these two languages stack up against each other, and which should you learn? Let’s find out.
JavaScript
JavaScript is, along with HTML and CSS, one of the core technologies of the internet. It lets us have interactive web pages and it’s the go to language for client side web applications. It’s used on almost all of the internet—as of 2018 95% of all websites used JavaScript. That web dominating list includes sites like Google, Facebook, and Youtube, which all use JavaScript.
JavaScript was created to “make web pages alive.” Made for web apps and sites, it was created by Brendan Eich working for Netscape in 1995. It is a high-level, interpreted, scripting language, which means JavaScript isn’t compiled; it’s interpreted on the spot at runtime. JavaScript is also an object oriented programming language, like C languages. It has curly-bracket syntax, dynamic typing, and first-class functions. It’s interpreter is built into web browsers, so without some help from a program like Node.js it will only run in a browser.
Ruby
Ruby is a dynamic and open source programming language. It has a focus on simplicity and productivity. Ruby was developed by Yukihiro Matsumoto and first released in 1995. It’s designed for ease of use, being dynamically and duck typed (if it looks like a duck it is a duck—a method of identifying types), multi-paradigm, high level, and interpreted. Ruby is also object oriented like JavaScript. It’s flexible because it allows programmers to modify how it functions by changing different parts of the language. It’s taken influences from Python and Pearl, and it has a lot of different uses.
Ruby is also well known for Ruby on Rails. Ruby on Rails is made for easily creating web apps, and it’s been around since 2011. It’s been used for social networks, blogs, and online marketplaces. It’s been used for AirBnB, Hulu, and Github. However, Rail’s popularity has diminished significantly since JavaScript has taken over the web.
What is Ruby on Rails?
Ruby on Rails is a framework written in Ruby for creating web applications. Frameworks are like a skeleton for web development, providing some of the basic structure and optional features that can be popped in and out. Another example of a popular framework is Angular, which is JavaScript based. It’s important to note, Rails is not a programming language, Ruby is. Rails is simply created using Ruby, and saves you a lot of typing.
Ruby on Rail follows the MVC (model, view, controller) style of framework. Models store the information, the view shows it, and the controller works between the two to control it. Ruby on Rails also comes with Gems. Gems are libraries of Ruby programs that have been made into a standard format for installation so that they are plug and play. There are thousands of Gems available, each providing for a unique and often required need when putting together a web app.
JavaScript Vs Ruby
Ruby | JavaScript |
Ruby is typically used for server side applications. | JavaScript is typically used for client side applications. |
Ruby is slower than JavaScript. | JavaScript is faster than Ruby. |
Ruby is easier to type and learn. | JavaScript is harder to type and learn. |
Ruby is object oriented with classes, almost everything in Ruby is an object. | JavaScript is object oriented but classless. |
Ruby is ‘duck’ typed. | JavaScript is weakly typed. |
Now that we have some background on learning Ruby and learning JavaScript, let’s look over them and figure out which we might prefer over the other. We will take on this task by comparing them head to head on a few different fronts.
Typing and Syntax
Ruby is built for usability. Its philosophy is that there is more than one way to do something. So not only does Ruby have a simple and easy to learn syntax, it has a syntax that’s designed to be used however you like. It’s very high-level, no variable declarations or semicolons, just easy to read code. It’s also more object-oriented than most other object-oriented languages. It’s so object-oriented that everything is an object, with methods and functions, even simple integers. Because of this, programmers can use method chaining; where a lot of code can be reduced into a little bit of code.
JavaScript isn’t terrible on the eyes, and it’s certainly not as painful to type as C languages, but it just doesn’t look as clean as Ruby. Ruby almost reads like a normal human language, setting it high up on the high/mid/low-level programming chart.
However, since Ruby is so loose in how it allows the programmer to use it, it can be difficult to pass code between programmers. Code that would normally be several lines can be reduced to a few, and then down to one line after that. While code that is this clean is prettier to look at, it can also be as hard to read—or harder to read—than the same code laid out in many lines. A single line of code that should be many can be difficult to decipher. Because it is relaxed, Ruby also allows for very inefficient methods of programming and doesn’t require anyone to adhere to a ruleset for programming, even if they should.
Also, because Ruby is so high-level, debugging can be a nightmare. Ruby is particularly abstract so finding what line of code is rubbing the interpreter the wrong way can be difficult. It’s not as easy as missing a semicolon, and often times it’s related to an unseen interaction that happens under the hood, or is equally buried under an immense stack call.
Performance
Generally speaking, there’s a rule when it comes to the performance of programming languages. The closer it is to machine code, the faster it’ll be. In this sense, the higher-level a programming language is, the slower it will be. This rule holds true with Ruby and JavaScript. JavaScript isn’t fast, not when compared to speedier, compiled languages, like C++. However, Ruby makes JavaScript look like a Ferrari. By benchmark, Ruby holds an average speed that is 50% to 200% slower than JavaScript (running with node.js). Some things that take under 30 seconds in JavaScript can take Ruby around eight minutes to finish.
It’s important to note that Ruby is slower in a benchmarking situation. This is when we throw something difficult to figure out and then measure how long it takes for the language to figure it out. In the real world when building a web app you won’t always need to solve Mandelbrot fractals. In this sense, many Ruby fans argue that Ruby is fast enough—that it’s only slow when compared to other languages—but that it functions fine otherwise. This topic is under intense debate, however, there are plenty of functional examples of Ruby performing fine: AirBnB, Kickstarter, or Apple.com to name a few. Performance generally only becomes an issue if perfect timing or large and complex calculations are necessary.
Community
Both languages have large communities behind them. JavaScript’s following is larger—it is considered the most used language by many metrics. It consumes nearly 95% of the internet and beyond. In available modules and packages it wins by the distance from here to the moon. While Ruby and Rails have a few thousand modules available, npm (for node.js, which again is JavaScript) has over 800 thousand modules, most of which are open source, and many of which are free for commercial use.
However, since Ruby is a far more user friendly language, so is it’s community. They are generally regarded as helpful and kind to beginners, as Ruby is a language that is also kind on beginners. Its community is also very active, meaning that it’s a fairly well documented language. And while the Gem library for Rails isn’t as huge as JavaScript’s catalog for node.js, the modules there are lovingly crafted.
Career Outlook
JavaScript rules the internet and while Rails is easy to use, it doesn’t have the performance or market share that JavaScript does. That said, Ruby is still a worthwhile investment for people looking to learn a new language. Ruby also functions very well as a second language, because Ruby is so easy to learn.
At time of writing Indeed.com features over 16,000 job listings for Ruby developers and programmers in the US alone. Ruby developers also make a lot of money. An average Ruby developer can typically expect to make somewhere between $50,000 to over $200,000 each year. According to Indeed, where all of those jobs are listed, the national average for a Ruby developer in the US is $123,154 per year.
Many people will tell you JavaScript is the best language to have in your back pocket, and I don’t think they’re wrong. Even if you don’t plan on becoming a JavaScript specialist, learning JavaScript will probably get you further in life as a developer, especially as a full stack developer. If you do plan to keep JavaScript as your focus, that’s not a bad idea either. The same site we used before, Indeed, has close to 60,000 job listings for JavaScript. On Indeed the average wage for a JavaScript developer is similar to Ruby: $113,615 per year.
Either choice has great prospects, but if you had to choose between the two JavaScript is the leading language. Unless the internet flips upside down in the next few years JavaScript won’t be going anywhere, and there will always be a need for more JS devs, while the future of Ruby is less certain.
About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.