Ruby - How Many Carats is this Gem?
Tags: ruby, javascript, programming, writing
Published: 2023-02-13 03:55:52

**Ruby is a flexible, high level, object oriented language that prioritizes ease of use for programmers, but how does it compare to tried-and-true JavaScript?**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i0a7947idol2godur8ib.png)

**PRO - Easy to Learn and Use**

Ruby was designed by Yukihiro Matsumoto with the goal of being simple, easy to read, and to allow for multiple approaches to achieve a programming goal. The language is known for being easy to interpret, with code being generally intuitive to grasp based simply on the syntax and plain English word choice for various commands, and often less verbose than other languages. To illustrate this, here is a snippet of JavaScript code which creates and then calls a function that will will greet the name passed to it as an argument, followed by a snippet of Ruby code which does the same thing:

JavaScript:
`function greet(name){
   const greeting = "Hello ${name}";
   console.log(greeting);
};
greet("Marcus");`

Ruby:
`def greet(name)
   greeting = "Hello #{name}!"
   puts greeting
end
greet("Marcus")`

As you can see, the Ruby code has a more natural feel to it, eliminating a lot of the more technical characters used by JavaScript, such as the curly braces and variable declaration keyword "const", and uses the keyword "end" to indicate where the function code stops. This makes it easier for a reader to parse, particularly with larger code blocks.

Of note, Ruby also allows more variation in syntax, allowing the programmer to choose what style they prefer. For instance, the function call in the code snippet above could have instead been written like this:

`greet "Marcus"`


**CON - Sharing Code Between Programmers can be Problematic**

Because of the design goal of allowing many different approaches to a coding problem, and especially the syntactic variations the language allows for, two programmers with different coding styles may find it difficult to make use of each others' code, at least by copying. This can make collaboration between multiple programmers on a single project a little more difficult than with other more syntactically strict languages, though it is worth it to note that Ruby does contain functionality to create plug-and-play libraries of programs, called "gems", which can easily be added to other Ruby programs to be made use of, which mitigates this downside to some extent.


**PRO - Flexibility**

While Ruby is most commonly used for GUIs and web apps/development, it is a highly adaptable language that can be used in a variety of situations. Since just about everything in Ruby is an object, even its base components can be altered or removed as needed to customize it to whatever end the programmer desires. This allows programmers to customize even the basic commands used in the program. 

For example, take this code snippet pulled from [the about section of the Ruby programming language webpage](https://www.ruby-lang.org/en/about/) which adds a "plus" method that can be used in place of the addition operation:

`class Numeric
  def plus(x)
    self.+(x)
  end
end
y = 5.plus 6`


**CON - Programs Run Slowly Compared to Other Languages**

Making just about everything an object does have its price: Ruby programs run notably slower than other coding languages, about 50-200% slower than JavaScript programs in fact. That may sound like a huge problem, but given that most code runs in almost imperceptible amounts of time regardless of language, this really only comes into play with code that requires extremely large numbers of operations to complete. Thus, while it is definitely an issue worthy of consideration, it's also true that it is not even a noticeable problem most of the time.

**PRO - Robust and Welcoming Developer Community**

Ruby is an open source language, a fact which draws many developers to it and generally encourages sharing and collaboration in its use. This has resulted in a large, friendly community which is very welcoming to those new to the language, be they beginner programmers or experienced ones looking to add a new language to their repertoire; the community continues to grow even to this day. This gives a lifeline to those still learning the language and those who have been using it for years alike, which is definitely a feather in Ruby's cap. A supportive community not only means updates, improvements, and sharing of tips and tricks, but also a place to go to for help or advice when a programmer's code isn't functioning properly despite their debugging attempts. And speaking of debugging...

**CON - Debugging can be Difficult**

Yes, even with help from the community debugging Ruby can be more difficult than with other languages. This is due in large part to some of the advantages mentioned earlier, namely the highly variable/adaptable syntax and the fact that Ruby is a simple to look at but fairly complex under the hood high level object oriented language. The variety in approach when using this language also means a wide variety of errors, with different users doing the same tasks potentially encountering very different hurdles to face. It is worth it to note that Ruby does have exception handling features to aid in error management, though the underlying complexity of the language means that those may not be enough in every situation.


**Conclusion**

The advantages that Ruby was designed to include are often double edged swords, but given how easy the language is to learn coupled with how adaptable it is, I would argue that it makes both a good first language for a beginner to learn and and a good "back pocket" language for any experienced programmer to pick up. While other programming languages like JavaScript might outclass it in certain areas, the fact is that Ruby is still a widely used language across a variety of coding professions, so learning it will certainly expand your portfolio without consuming too much of your time.

<u>Sources</u>:

https://www.ruby-lang.org/en/about/
https://blog.boot.dev/javascript/ruby-vs-javascript-which-language-should-you-learn-first/
https://careerkarma.com/blog/ruby-vs-javascript/
https://careerkarma.com/blog/what-is-ruby-used-for/
https://activebridge.org/blog/what-do-experienced-developers-think-of-ruby-the-ultimate-ruby-guide
https://www.youtube.com/watch?v=UYm0kfnRTJk
https://www.youtube.com/watch?v=vFEPkXybAlo