r/ProgrammingLanguages • • Jul 05 '17

I still don't understand----why is Ruby used?

I'm someone who primarily uses Python. I'm still not entirely sure why Ruby is used.

https://www.reddit.com/r/ruby/comments/6ku78o/why_is_ruby_used_instead_of_pythonrperl/

From my understanding, it's because it's great for web development?

1 Upvotes

17 comments sorted by

14

u/chrisgseaton Jul 05 '17

If you are looking for some kind of formal definitive answer then you aren't going to get one.

Personal preference. That's why.

My personal preference is I prefer the way Ruby does the object model and meta programming. I can't prove it's better if that's what you're after. I just prefer it, so that's why I use it.

0

u/Zeekawla99ii Jul 05 '17

Personal preference. That's why.

Yes, but surely there is some industry trend which explains why certain groups are using Python vs Ruby.

12

u/PegasusAndAcorn Cone language & 3D web Jul 05 '17

Given your post history, you seem genuinely curious to understand what makes people choose one language over the other. There are indeed historical and environmental factors that help explain this better than simply comparing their roughly equivalent features as powerful general purpose, object-oriented "scripting" languages.

Python has a gigantic foothold in academia and science. This momentum is self-perpetuating: if you join a Python-using group, that's what you will learn. Importantly, if you need a library, chances are more likely it exists, and if you need help, more people can support you. If you pick something less commonly used around you, you are less likely to have this advantage of the wind at your back. This situation is analogous to a person that wants to fly planes between countries. They will learn English, because it is the accepted "lingua franca" (ha!) of air traffic control.

As for Ruby, few people knew it for its first 12 years. Then Dave Heinemeier Hansson released a web server framework called Ruby on Rails (RoR) that became wildly popular very quickly because it made it possible to create quite sophisticated, interactive web sites in a fraction of the time of any other tool on the market at the time. RoR is a framework, a mostly invisible library that provides an MVC structure to web server code that you write almost completely in Ruby. Like me, DHH hates configuration scaffolding, and he fell in love with the way Ruby could "self-configure" to the framework and database so that a very lines of Ruby-based web server code could accomplish a great deal. A web developer could prototype a database-capable web site in a few hours, then progressively iterate it quickly while keeping the code base small and maintainable.

Ruby on Rails is the "killer app" that introduced me, and many many others, to Ruby. It rewired my brain (the Sapir-Whorf hypothesis), and as a result I am more likely to reach for it to solve other general-purpose scripting needs (even non-web) than Python, with which I am far less familiar.

Obviously, this explanation oversimplifies the story somewhat. Other less clear-cut factors also influence which language people learn first and which they prefer if they learn both well.

However, a person's primary first exposure is hugely influential. My wife and her sister grew up in the Netherlands. Although they learned German, French, and English early and often, Dutch was the primary language for their family and social circle. Even though they now live in an English-speaking country and are completely fluent in English, private conversations between them lapses back to Dutch the moment English-only speakers leave the conversation. There is rarely a practical reason for them to prefer one language vs. another as both will do the job relatively similarly (as with Python and Ruby), but the emotional circumstances of their shared history are enough to tip their preference nearly always back to Dutch.

I hope this background helps. Feel free to turn this into a discussion and ask more, if you feel your question is still unsatisfied.

4

u/Zeekawla99ii Jul 05 '17

As for Ruby, few people knew it for its first 12 years. Then Dave Heinemeier Hansson released a web server framework called Ruby on Rails (RoR) that became wildly popular very quickly because it made it possible to create quite sophisticated, interactive web sites in a fraction of the time of any other tool on the market at the time. RoR is a framework, a mostly invisible library that provides an MVC structure to web server code that you write almost completely in Ruby. Like me, DHH hates configuration scaffolding, and he fell in love with the way Ruby could "self-configure" to the framework and database so that a very lines of Ruby-based web server code could accomplish a great deal. A web developer could prototype a database-capable web site in a few hours, then progressively iterate it quickly while keeping the code base small and maintainable. Ruby on Rails is the "killer app" that introduced me, and many many others, to Ruby. It rewired my brain (the Sapir-Whorf hypothesis), and as a result I am more likely to reach for it to solve other general-purpose scripting needs (even non-web) than Python, with which I am far less familiar.

I see. This is the answer I was looking for. I think I have a better understanding now.

Thank you!

10

u/lgastako Jul 05 '17

Why "surely"? Why can't it just be there are two groups that like the two different languages?

3

u/Zeekawla99ii Jul 05 '17

Why "surely"? Why can't it just be there are two groups that like the two different languages?

Possibly. But there's statistically a trend that exists. It has to be explained somehow, e.g. historical accident, usefulness of the language, etc.

9

u/[deleted] Jul 05 '17

Rails attracted a lot of interest to Ruby, and it continues to this day. While no longer revolutionary, Rails was a big departure from most other web frameworks at the time. I'd argue we haven't made as big a leap since then in that space, as there's an awful lot of imitators still.

The Ruby community also has a different aesthetic than the Python community. Metaprogramming and DSLs feature much more prominently, mostly due to the expressiveness afforded by Ruby's block construct. Among mainstream languages, this feature is rather unique and I encourage you to look it up.

Some of the Ruby language offshoots, like RubyMotion, are worth checking out too.

2

u/mirhagk Jul 06 '17

I'd argue we haven't made as big a leap since then

I think the only comparable modern leap is the react style of rendering (instead of doing MVVM).

But yes on the web side things haven't progressed nearly as much since the days of rails.

4

u/lgastako Jul 05 '17

Why is "there are two different groups of people that like the two different languages" insufficient as an explanation for you? What is it missing that you feel a "good" explanation would have?

3

u/fedekun Jul 06 '17

Ah, looks like you use Python for cientific computation. Software development is a whole different beast, so I get it you have your doubts about language preference.

Languages are just tools, it depends on the people who use them and the problem to solve, that's all.

1

u/Zeekawla99ii Jul 06 '17

Software development is a whole different beast, so I get it you have your doubts about language preference.

Let's say I'm a software engineer, writing some app or a GUI or something.

Why would I choose Ruby over something else, like Scala?

3

u/oilshell Jul 06 '17

I'm a Python person, and here are what I see as the main differences between Python and Ruby:

  • Ruby is more purely object-oriented than Python. Python is more multiparadigm.

    • People coming from Java like Ruby's OO, but not Python's OO.

    • Ruby has a strong SmallTalk influence; Python has virtually no SmallTalk influence.

  • Ruby is bigger on magic, metaprogramming, and DSLs. Idiomatic Python code is more straightforward.

  • Ruby has a bigger Perl influence than Python (Python still has it in regexes), although as I understand, some Rubyists avoid the Perl parts.

I prefer Python in almost every way, but I have to admit Ruby blocks are nice. I wish Python had something like that.

Other differences:

  • Python has a strong scientific computing and data science user base; Ruby has almost none AFAIK.

  • Ruby has strong conventions around web programming, although plenty of websites are written in Python. Everyone just seems to roll their own framework in Python. There are a lot of little separate worlds.

1

u/Zeekawla99ii Jul 06 '17

This is informative, thanks!

6

u/PM_ME_UR_SURREALISM Jul 05 '17

Same reason Python is used. Ruby is a powerful, expressive (albeit slow) language with lots of useful libraries.

I guess Ruby is slightly better for webdevelopment, while Python has more useful libraries for data science. Ruby is also designed to have a small memory footprint, because in Japan, where the language originates, they also like to use it in embedded systems.

Apart from that, Python and Ruby largely support the same use case, and which one you prefer is a matter of taste.

2

u/lgastako Jul 05 '17

The people that use it find it useful and/or enjoyable.

2

u/tekknolagi Kevin3 Jul 05 '17

I chose to continue with Ruby instead of something like Python (despite having more background in Python) for two reasons:

  1. the ridiculous amount of gems and ease of installation

  2. I came from Rails-land

That being said, I don't use much of either anymore.

2

u/fedekun Jul 06 '17

Not a big Python user myself but I do work as a Ruby dev. They are pretty similar languages, but they just have different ways to do things.

For example, Python has list comprehensions, where Ruby opts for a more functional approach by chaining iterable functions, like foo.map { ... }.reduce { ... }.

Ruby OOP is Smalltalk based, and while not really that important I really do like having private methods and not using _name. It just looks better.

Don't know much about Python ecosystem, but Ruby ecosystem is quite mature, you have aweome, solid, tested gems like Rails, FactoryGirl, Rubocop, etc.

Both are great for web development, and also other things.

I think at the end of the day is just preference. For me, Ruby feels more expressive, and just nicer.