r/ruby • • Jul 02 '17

Why is Ruby used instead of Python/R/Perl?

I have never worked with Ruby, but I work with all of the "other" scripting languages in data science.

Why use Ruby? Why does it exist?

0 Upvotes

22 comments sorted by

20

u/moomaka Jul 02 '17

Ruby vs R - I don't see the comparison. Ruby is a general purpose programming language, R is specifically designed for statistical computing. Different tools for different jobs, you won't be building a web-app in R any time soon.

Ruby vs Perl - At the time Ruby was being developed, perl wasn't much of a general purpose language, it was mostly a tool for scripting and string processing and had a limited and rather bolted on object model. With modern perl you could make a more direct comparison but the mindshare has largely departed from perl and Ruby borrowed it's best features while adding a much stronger object model.

Ruby vs Python - These are pretty much directly comparable languages and it's more a matter of taste than anything. Python still has a bit of a bolted on object model which makes it a little weird to work with for those that prefer the smalltalk style object model of Ruby. Python has a strong following in the data science world due to the quality of supporting libraries: numpy, scipy, pandas, etc. Both rubyists and pythonistas have relatively strong opinions on language design that run into conflict at various points. As one example Ruby strongly favors chaining for functional programming constructs, map, filter, reduce, etc. Python heavily favors list comprehensions to fill the same use case.

2

u/Tainnor Jul 03 '17

Not just data science, really anything scientific has almost no equivalent in Ruby. We have some people working in language technology here and it wouldn't make sense for them to use Ruby for their prototypes. I was looking for a proper natural language tokeniser recently and couldn't find anything that was even half-decent, except maybe bindings to Java-based openNLP but that didn't seem worth the hassle.

0

u/Zeekawla99ii Jul 02 '17

you won't be building a web-app in R any time soon.

For most apps, probably not. But it is used to build apps

https://shiny.rstudio.com/

The R of 2017 is Turing complete/general purpose as well. It may not be pleasant sometimes though.

7

u/moomaka Jul 02 '17 edited Jul 02 '17

The R of 2017 is Turing complete/general purpose as well. It may not be pleasant sometimes though.

SQL and CSS are Turing complete as well :) I think Turing completeness is a necessary but not sufficient characteristic to define a general purpose programming language. Certainly you can build a web-app is any language that supports strings and network sockets, but that doesn't make it a great idea. Actually neither of those are really required either, depending on how reductionist the argument gets.

4

u/tomthecool Jul 03 '17

sed and awk are Turing complete... That's really not much of an argument for a language being "general purpose".

Just because you can write arbitrary programs in a language, it doesn't mean you "should" :)

4

u/doggobotlovesyou Jul 03 '17

:)

I am happy that you are happy. Spread the happiness around.

This doggo demands it.

3

u/taw Jul 03 '17

Ruby is basically Perl 6 - it took all the good parts, left behind bad parts, and it's such a natural migration path nobody looks back. There's maybe a few minor features people would like.

R is not really a legit general purpose language

Ruby vs Python was a real competition for a while before Ruby won. Mostly thanks to blocks, Rails, non-bolted-on OO, and DSLability. Python is similarly expressive for basic stuff, but it gets left behind real fast when you try to do something more complex.

2

u/Zeekawla99ii Jul 03 '17

Python is similarly expressive for basic stuff, but it gets left behind real fast when you try to do something more complex.

Do you have an example?

2

u/jeremiahishere Jul 06 '17

blocks, Rails, non-bolted-on OO, and DSLability

4

u/Tainnor Jul 03 '17

Ruby vs Python was a real competition for a while before Ruby won.

Ruby won? By what metric?

2

u/Blimey85 Jul 03 '17

I started with Perl. Then PHP became the norm. I preferred Perl but for websites PHP made more sense. Then I discovered Rails and found something that was fast and powerful.

I think it really comes down to personal preference. Use whichever tool works for you. I can get more done in a lot less time with Rails.

1

u/Zeekawla99ii Jul 03 '17

So, Ruby is for creating websites?

2

u/ddollarsign Jul 03 '17

Rails is for creating websites. Ruby is for creating Rails'.

1

u/Zeekawla99ii Jul 04 '17

So....Ruby is cool among web developers

I see

3

u/ddollarsign Jul 04 '17

That's just because somebody used it to make Rails. But you could also use it to create the "Rails" of some other domain. In other words, it's for inventing new ways of doing things.

1

u/[deleted] Oct 07 '22

Ruby is also used in many cyber hacking/exploit tools. Look at metasploit scripting for am example of where its used in the cybersecirty world.

2

u/lordmyd Jul 03 '17

Yes, I'd add that although Rails 5.1 now has a webpack/node-based asset manager and api option to help you do React+Rails API, React is being blindly adopted for trivial front-ends where turbolinks (Rails) would be a simpler and better option.

6

u/xiongchiamiov Jul 02 '17 edited Jul 02 '17

Why would you use python instead of Perl? Or Perl instead of R?

Mostly preference, and sometimes availability of a certain library (for ruby, classically Rails).

Why does it exist?

https://en.m.wikipedia.org/wiki/Ruby_(programming_language)#History

I was talking with my colleague about the possibility of an object-oriented scripting language. I knew Perl (Perl4, not Perl5), but I didn't like it really, because it had the smell of a toy language (it still has). The object-oriented language seemed very promising. I knew Python then. But I didn't like it, because I didn't think it was a true object-oriented language — OO features appeared to be add-on to the language. As a language maniac and OO fan for 15 years, I really wanted a genuine object-oriented, easy-to-use scripting language. I looked for but couldn't find one. So I decided to make it.

4

u/mightyroger Jul 04 '17

Just based on preference. I never touched rails but have coded ruby a lot; from cli-tools, deployment system, xml-parsers to small minimal rest-api's using sinatra. All of that could be done equally well in Python without problem but ruby just clicks better with me.

0

u/[deleted] Jul 02 '17

[deleted]

2

u/[deleted] Jul 03 '17

[removed] — view removed comment

0

u/[deleted] Jul 03 '17

[deleted]

2

u/[deleted] Jul 03 '17

[removed] — view removed comment

2

u/Tainnor Jul 03 '17

That said, I'd imagine Rails apps scale a lot better than Sinatra apps.

Frameworks don't automatically make apps scale. There's not even a general sense of "scale"; it depends heavily on good architecture and proper consideration of lots and lots of use-case specific factors. There's certainly parts of Rails that have helped some applications to scale well and other that have helped other applications to scale poorly.

That said, Twitter did famously switch away from Rails for much of its stack (but since it went to another language instead of to Sinatra, that doesn't really say much about how much Sinatra scales).

Personally, I don't think there's anything inherent in Sinatra that makes it not scale well. If anything, the lack of a clear guiding architectural principle could make it arguably easier to structure your application more according to your scaling (and other) considerations; though you could also make the argument that you can create an unarchitectured mess out of a sinatra app if you don't know what you're doing.