I'm a Java guy and I really don't like Ruby. But a lot of people really love it. I just don't think I understand it very well, and my ignorance makes me hate it. I'm not looking to start a flame war, I'm genuinely curious as to why so many people like Ruby.
In my experience, any time I've tried to use Ruby, or a framework like Rails or Jekyll, or a tool like Vagrant or Fastlane with a Ruby config, I just find myself hopelessly confused by the very things that are touted as "Ruby's great features", and spending endless hours debugging things that turn out to just be some strange quirk of "Ruby magic".
So please, tell me why do people like Ruby, and do people ever "learn to love it" and actually pick it up after years of working with a more "traditional" or C-style language, or is it only people that started their career in Ruby that truly love it?
Top comments (16)
Ruby's flexibility and expressiveness makes it great for writing DSLs and frameworks and for writing code with very little boilerplate. The added complexity of the DSLs and frameworks often makes it hard for new Ruby devs to know what's going on.
When I was new to programming, I learned C, plus a little bit of PHP and Python. When I started using Ruby, it was just so EASY. I found myself wondering why other languages are so verbose or require byzantine syntax. I still can't understand why anyone would make a language without string interpolation.
Part of the reason Ruby seems like magic is because of its consistency in a few key areas. Everything is an object, and every expression returns an object. This leads to consequences such as implicit return and method chaining. These aren't features, necessarily, but natural consequences of the above principles. These things make perfect sense if you learned Ruby from the ground up, based on Ruby's own principles. They may be less obvious if you are trying to apply your current programming paradigm to Ruby.
Certain principles can be hard to think about in Ruby. I'm pretty sure that when Matz designed it he wasn't concerned about explaining pass-by-reference vs. pass-by-value. That's generally because Ruby encourages you to think in other ways, and that can be painful for those with experience.
I think I had an advantage learning Ruby early in my programming journey, and in learning it as a language rather than through Rails. I used Ruby Koans and CodeAcademy.
Anyway, I don't know why I typed all that. I should have just posted this link and shut up.
I was going to answer something similar to this answer, but more focused on the simplicity of its sintax.
10+ years experienced rubyst here. before it I've used C/C++/C#/Python/PHP and so on. doing web development, I was amazed by Rails'
do super SQL queries in only two lines of magic Ruby code
and so I've started using it as my main language for over a decade. with time, I've also learned to tame that beast and use it in the right way.as others already said, Ruby is a very expressive language, it lets you to write code that looks like plain english (even without using/writing a DSL).
it also looks easy at first glance, after all you can hide complex logics behind all that syntactic sugar (again, built-in or through DSL).
however, the truth is that Ruby is not an easy language, or at least, you need to know it very well if you want to master it and know what is really happening under the hood.
newcomers are often attracted by that magic, they want to learn it and start abusing DSLs, metaprogramming and all the magic stuff that Ruby offers. with time, they will learn to be more cautious about those features, to avoid shooting on their own foots :-P
my 2 cents :-)
I hated Ruby the first time I tried to learn it (coming from Python). I think that the main reason was that I tried to learn Ruby and Rails all at once, diving right into Rails without getting a solid Ruby foundation. I also hated the magic and the voodoo that you had to just "assume it worked."
So I gave up.
I came back to try it again about a year later, because I really wanted to like Ruby. This time, I started with Ruby Monk, which is a great way to learn because it teaches you to do things "The Ruby Way(s)." You learn that there's not really "magic," just that some things are implicit, but predictable. Things like, "you can call a function like
puts('hello')
orputs 'hello'
, and both are OK. Once I had a solid foundation, Rails made a lot more sense, and I could see through and behind the magic. I didn't have to trust that it was working, because I knew what things were doing behind the scenes.Now, I love Ruby! I love it because it can take really complex tasks, processes, or concepts and the code comes out looking like what you might say out loud when explaining it to your little rubber duck friend. Ruby is the only language that I've written in that I finish a block or a method and just get this feeling of
Ahhh... that's nice. Like when you smooth the sheets on a bed down just perfect and everything is flat and smooth and all is right with the world. (Okay, maybe that example says more about my personality than how nice Ruby is, but hopefully you get the idea.)
Back in 2001, freshmen year at college, I was wondering why simple "Hello World!" in C had to look like:
Back in 2003, I was wondering why a simple "Hello World!" in C++ had to look like:
Back in 2007, I was wondering why the simple "Hello World!" in Java has to look like:
In 2008, I found out that it can look like:
I was never looking the other way!
Btw., I am an engineer.
I read the following post and found myself agreeing with the notion presented within:
mkdev.me/en/posts/the-three-types-...
Essentially, it argues that there are three base mindsets wrt programming and the languages you like with mindset:
I am very much the engineering type and regardless whether there are really 3 types or whatever, consider that programming is done by different people with very different minds and they like the languages that come naturally to their way of thinking. It's not better or worse, but different angle of approach.
I'd say Ruby optimizes for brain to code time, but it only works if you know and like it I'd say.
I like DHH's line about Ruby "fitting one's brain". As a Rubyist that seems to be why I keep going back to it.
Ruby was the first language I learned that felt really fun. It didn't feel like I was fighting a rigid system to get things done, and I wasn't writing unnecessary glue code or helper methods everywhere.
In school I had originally learned Java and then did about 5 years of PHP/JS development work. Finally I got a job doing Ruby after being a fan of the language since college. Ruby just works with my brain instead of getting in the way of it.
I asked myself the same question about 10 years ago when Ruby on Rails first blew up on the scene and all the devs at Wordcamp were doing seminars on switching their stack to it. It was hard to envision why people would leave PHP for another language. And particularly at the time, I was just learning PHP, so it pissed me off that I had to learn yet another language/syntax 😣
Now reflecting, I see it like the emergence of Node. People dropped other languages like hot potatoes because of the ease and simplicity Node exhibits for certain functionality, and it's efficiency in accomplishing them (compared to PHP). Sure, I can build an API in PHP, but I can build it in Node/Ruby and have it scale better -- and interact with other devops services (possibly in other backend language I might prefer too like C or Python).
I came from Java and C/C++. I've been using Ruby on Rails for a while now and just have not learned to love it. In fact, I've been trying to weed it out of my projects with few exceptions.
Without getting into the weeds (I want to keep this short), my least favorite thing in the Rails world is ActiveRecord (and AR migrations). It's mostly the same reasons I never liked Hibernate in the Java world and fell back onto MyBatis (and Flyway). Complex queries in ActiveRecord (and Hibernate) are an absolutely nightmare, but trivial and much more common queries are fast and easy.
When it comes to basic, web-facing entry points for an application I can still see it used. When it comes to microservices and wanting performance in systems it just can't beat other languages. For large data transformations and hefty calculations I've had more luck using languages focused on those things as their speciality.
That being said, I think we live in a world now where using a single language to accomplish everything in your system is ludicrous. The days of "we are an XYZ shop" are almost over. A good cloud architecture uses whatever is best for the task at hand. For a website or a prototype? PHP and Ruby on Rails are perfect. Any engineer worth their salt, though, knows AT LEAST 3 languages inside and out.
In a lot of systems I've worked on lately I've seen a mix of Java, Go, Python and even some C# in some places. For people doing nifty things with Nginx I've seen some neat C, too. Ruby comes in mostly when I see people using Chef, Terraform, etc. where I think it is a great fit.
Monolithic systems are on the out and microservices are on the in. RoR/Passenger, RoR/Unicorn and things like Java/JBoss, Java/WebLogic, etc. are LESS necessary in many enterprise apps now. They absolutely have their place, but things like Kubernetes help alleviate some of the headaches they caused as well.
There's some other things that bug me about Ruby "stuff I see frequently": not being strict type safe (I dislike dynamic typing pretty strongly), overuse of hashes instead of classes (except in the case of things like parsing JSON where it is great), lack of distinction between arrays, lists, sets, vectors, etc., using AR all over the code instead of having shared DAO services, using AR migrations instead of direct SQL (heck, we have Docker now so you don't need to test on SQLite and deploy on MySQL) and some other stuff.
Again, I see it's place, but I just don't love it. I can see its use for scripting, but I prefer Bash for that and fall onto Python when Bash doesn't cut it.
I dunno. Just my opinion.
I'm a python guy, But when it comes to a full stack web app, I prefer Ruby on Rails.
Ruby is simple and easy to learn
Easy to write anything you want to,
Great Community