DEV Community

Cover image for Pitch me on Ruby
Ben Halpern
Ben Halpern Subscriber

Posted on

Pitch me on Ruby

Part of a new series! Feel welcome to dip in and weigh in on a past question.

Let's say I've never used Ruby before. Can anyone give the run down of what the language does and why you prefer it? Feel free to touch on drawbacks as well.

Top comments (13)

Collapse
 
n8chz profile image
Lorraine Lee

Ruby is my comfort language. That may say more about me than about Ruby. For whatever reason, if I have a need to compute something algorithmically, and it's something reasonably simple, Ruby is what I reach for, mainly because in Ruby I'm less likely to hit the speed bump called "reading the manual." But that's because I've memorized a larger chunk of the Ruby manual than (say) the Python manual (I'm a student of mathematics so in theory I should be more in the Python orbit). So very likely it being my comfort language is not something about Ruby per se. As I said in my "Python pitch" in your series, I edit Python faster than I edit Ruby, but I think so much faster in Ruby that Ruby is still my comfort language. Doing every single Ruby exercise on Exercism is probably what addicted me to Ruby.

Collapse
 
aclarembeau profile image
aclarembeau

I've been using ruby quite extensively over the past 3 years, and I would describe it as the following:

Ruby is a modern programming language with a clean syntax.

Nothing more, nothing less. It's quite similar as Python, but with a few more syntaxic sugar (it allows you to write your code in many alternative ways, that I often find very pleasant to read, compared to other languages, which are generally more "rigid").

The places where it shines is when you has to write web applications, thanks to the beautiful Ruby on Rails framework, that allows, thanks to a well defined architecture, and good balance between presets and flexibility to quickly build new applications (and it comes with a very good ecosystem of libraries, called "gems")

So, to summarize:

  • It's pretty neat to read
  • It is really good to quickly build application with the Rails framework

Of course, it has drawbacks too, like:

  • Not so good support for concurrency (afaik, it doesn't have light threads with promise await like in Javascript for instance)
  • Relatively recent support for types (in case you need typing, Ruby is not always the right choice)
Collapse
 
sylwiavargas profile image
Sylwia Vargas • Edited
Collapse
 
pinotattari profile image
Riccardo Bernardini
  • Minimal surprise and a very consistent structure.
  • It has a flexible syntax that allows you to use the best solution depending on the context, for example,
a.each {|x| puts(x)}
Enter fullscreen mode Exit fullscreen mode

vs.

a.each do |x|
   puts(x)
end
Enter fullscreen mode Exit fullscreen mode

or

if foo 
   return
end
Enter fullscreen mode Exit fullscreen mode

vs.

return if foo
Enter fullscreen mode Exit fullscreen mode
  • Moderately strongly typed; not as much as Ada, but at least it does not try to be "smart" converting everything to everything else (yes, JS and PHP, I am looking at you...)
  • Duck typing is maybe the best middle ground for a language like Ruby: it offers you some protection, while allowing some flexibility
  • Strong reflection features. Although I wouldn't use them for critical code, they are too fun to use 😄
  • yield allows for some nice construct like the File.open do ...
  • It does not make spaces significant... well, almost. If you put some space between a procedure name and the parenthesis, you could have some trouble; but at least it is not like in Python or Occam where white space plays a critical role
  • Really nice for programs that are too complex for a shell script, but that would be an overkill to write them in something more structured (e.g., Ada, C, C++)
  • Regexp make really easy to process text files. For a small script to extract data from a text file, Ruby is my first choice

On the cons side, I would not suggest it for medium complexity code and/or code with a "long life" that will require maintenance in the future. Duck and dynamic typing is nice for its flexibility, but when the code is too complex it gets difficult to keep track of the type of the different variables and this makes maintenance more difficult (at least, according to my experience)

Collapse
 
wiseai profile image
Mahmoud Harmouch

Being the co-founder of Forem, which technically implies that you are omniscient about the language, i think this is the best occasion to pitch us on ruby.

Collapse
 
k_penguin_sato profile image
K-Sato • Edited

Active Record(IMO still one of the best ORMs)

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️ • Edited
$ ruby -e 'puts "".methods.count'
183
Enter fullscreen mode Exit fullscreen mode

Whether this is a good or a bad thing depends entirely on what you need the language for 😉

Collapse
 
n8chz profile image
Lorraine Lee

Ruby is a force multiplier.

Collapse
 
polterguy profile image
Thomas Hansen

Jekyll ...? ;)

Collapse
 
xuwupeng2000 profile image
Jack Wu

如果我自己开一个公司,我肯定用ruby,因为效率高,写着舒适。

Collapse
 
canolcer profile image
Can Olcer

There are two main reasons I fell in love with Ruby: 1) Ruby optimizes for developer happiness, 2) Ruby on Rails

Collapse
 
w3ndo profile image
Patrick Wendo

General request, could you do a pitch me on Elixir series?

Collapse
 
kojix2 profile image
kojix2

Ruby has a lot of room to reinvent the wheel. This is one of the reasons I love Ruby.