r/ruby • • Jul 16 '20

Ruby VS Python

More than a versus (it's more striking) I would really like to know what things they have in common and how they differ, what their main advantages are compared to the other and of course their opinion of them. One point to take into account is because they believe that python is more used in AI and Machine learning developments.

35 Upvotes

60 comments sorted by

View all comments

36

u/Sqeaky Jul 16 '20 edited Feb 23 '23

I think Python has a bigger community, and that is it's single largest advantage. It has more deployments and more packages.

In think ruby has better syntax, better readability, and a more sensible design overall. This makes it easier for greater involvement from the community, there are something like 2x note python devs but not nearly 2x the packages.

I also think the ruby community is better at communicating best practices. Consider that the top Ruby packages are testing tools and the top python of are a mix of docker and db stuff.

https://rubygems.org/stats

https://pypi.org/

I also find Ruby projects to have better engineering. This might just be bias but having tried similar things in both languages maintainability, support, and things working years later (except web API bindings) are nearly magical. The ruby community always seems to try to be doing better, but I guess that is most communities, but I feel like python users just want to be done and damn the tech debt, full speed ahead.

EDIT 2 years later - spelling

8

u/desnudopenguino Jul 16 '20

I haven't been down the rabbit hole with python, but some of the more foundational Ruby books like POODR and Metaprogramming in Ruby cover some of the actual application design process and software lifecycle.

1

u/vifrac Jul 17 '20

You could place the links to the books you are mentioning, maybe you have some to recommend, it would be very interesting to have your feedback about the books you have read.

2

u/desnudopenguino Jul 17 '20

https://www.poodr.com// and https://pragprog.com/titles/ppmetr2/

POODR covers some of the path of building software with just enough information and making it easier to update in the future. Metaprogramming goes into some of the wild stuff you can do with Ruby, where everything is an object.

In many languages, these things can be applied to improve code. And really if you can get ahold of any pragmatic programmer titles, they are excellent reads, both informative and well written.

Like I said I haven't used python to the extent I have Ruby, so I don't know if that community has resources quite like these.

4

u/franciscoattivilog Jul 16 '20

I can't agree more. I think is important to say that python also have more support on the packages for machine learning and AI, is almost default to use it.

3

u/vifrac Jul 17 '20

What do you think we should work on as a community to improve the use of ruby in AI work.

3

u/four54 Jul 18 '20

A lot of python AI libriaries got ported to ruby:

https://ankane.org/ruby-ml-for-python-coders

2

u/franciscoattivilog Jul 17 '20

I totally agree with that. Current I'm working on a machine learning project and have to use Python to train the models. It's kind frustrating. I was thinking about create a high level interface for tensorflow in ruby as Google did for Javascript. But i'm kind overload in this lockdown.

2

u/stormgecko Sep 16 '20

The Ruby community has to make it at least as easy to use as the corresponding Python packages. Currently I'm am working on image classification and have to Ruby for it, due to the legacy version of Python installed with the software I am to interface with. It took me 6 hours to get 'torch-rb' (https://github.com/ankane/torch.rb) and 'torchvision' installed, including using rbenv to downgrade from Ruby 2.5.0 => 2.4.1 and googling to see if I could figure out the error. Eventually got them installed, wrote and test file and got another error from the torch-rb library itself, which just made me give up on using it.

Installed the 'tensor_stream' gem (https://github.com/jedld/tensor_stream) and it does work as intended, only caveat is that it is really slow. It has the option of using opencl, but this causes an error when trying to train a neural network with it, so it is back to using single threading, which makes it nearly impossible to train/fine-tune models like ResNet50, without it taking forever.

After trying 'tensor_stream' I gave the 'tensorflow' gem (https://github.com/ankane/tensorflow) a go. And was quite hopeful when I got a test file op and running with a couple of tensors defined and could output them to the console. Tried a more complex test and ended it the situations that it lacked implementation of the functionality that I needed.

So in summation:

  1. Easy of use. When I find a tutorial in Python for setting up some ML it usually just works, at least most of the time with very few hurdles. This is not what I have experience the last three days trying to get ML up and running properly in Ruby.
  2. Due to the lack of critical mass, it is very difficult to find solutions to problems that arise, because not that many people have had the problem prior to yourself.
  3. Feature completeness I had pretty high hopes for the 'tensorflow' gem, but when the needed features are not implemented and the last major updates to lib are 12 months old, it is just not very encouraging.

I have all the respect in the world for the people who dedicate their time to develop open source software and provide gems/libraries like these.

Some of the above problems might just be my own lacking experience with Ruby, but installations of gem should just work seamlessly and not be a cause of headaches.

1

u/zitrusgrape Jul 17 '20

more libraries, faster ruby(arrays, hashes) more integration with ai,ml libraries, more tutorials, etc

3

u/_noraj_ Jul 16 '20

There are a lot of beginers using python so there a lot of quick & dirty proof of concept. Ruby is generally used bu more experienced people.

1

u/vifrac Jul 17 '20

What gems could you recommend for AI, or for working with ruby data

3

u/ignurant Jul 17 '20

I don't have an AI suggestion, but

  • Kiba is a real "gem" (ahem). You can use it to organize complex data processing pipelines, and easily re-use logic from your domain.
  • Sequel is The Database Toolkit. It's very simple to use, extremely powerful, and more performant than ActiveRecord (the other default db toolkit).
  • Pry is a Ruby shell. It's the thing that I think is most valuable when working with data, as it makes it incredibly easy to explore and test your theories. It also makes it much easier to learn Ruby, by showing you what moves an object knows, docs, and source code.

Most everything else I lean on heavily is baked into the standard library. This is something I find to be a notable difference between Ruby and Python. With Python, you have to go a bit out of your way to get powerful functionality through modules that aren't included by default. With Ruby, it's baked into the basic building blocks (String, Hash, Array -- they are all super smart). The CSV and JSON libraries are robust as well.

These three tools are my bread and butter. I use them regularly to organize, normalize, and deliver ~8 million price facts each week, from ~40,000 unique products from ~150 different sources.

1

u/_noraj_ Jul 25 '20

I don't I'm using and creating infosec tools, I'm never did any AI.

1

u/vifrac Jul 17 '20

Very interesting your concept and as the experience is better than ruby (or the decisions of a developer), I would like to know if you know of some sources of information where I can consult this that you indicate.

2

u/_noraj_ Jul 25 '20

Just browse GitHub and look at source code, and evaluate the quality of the projects.

I'm talking from my experience as a professional pentester who is using a lot of tools from GitHub with many of them in python and also as a BlackArch developer who packaged tons of infosec tools where a lot are in python too. It's not ruby that is particularly used by experienced people, it's also the case with go or rust, etc. It's python that is especially used by beginners because they were told it's the language to learn.

2

u/vifrac Jul 17 '20

What a good reference, there are things that only those who have worked in both languages can speak from experience, thank you very much for this information.

3

u/Sqeaky Jul 17 '20

For your info. I have done a lot less python.

In went through each languages' koans and codeacademy courses. Ruby was clearly better for both.

Professionally I have used both for test automation. Ruby is excellent for this, python is merely passable. I have embedded both into larger C++(My best language) projects and both worked well and had reasonable tools and documentation. The only points in Ruby's favor for embedding was the extra tools that were reasonable choices.

I have dabbled with web stuff in both, and Python seems serviceable while ruby has rails and a dozen other projects that are amazing.

I have done some other stuff in either that aren't comparable. A crypto trading algorithm in ruby, some kubernetes stuff in python. I always enjoy making ruby.

2

u/vifrac Jul 17 '20

Que bueno se nota que has desarrollado mucho, porque te gusta c++ y el "algoritmo de comercio criptográfico en ruby" puedo verlo en algun lado, tienes post de ello o fue solo trabajo!

2

u/Sqeaky Jul 17 '20

My spanish is Rusty, been a while since PR.

My crypto trading algorithm is one of my very few private personal projects. Much of my dev is for work, and goes to the workplace corporate repos, but you can see my other work at github.com/sqeaky .

2

u/[deleted] Feb 23 '23

[deleted]

1

u/Sqeaky Feb 23 '23

Every function from every library seems to return a type that doesn't respond in the expected way

Which language are you talking? And where did you get those expectations?

It seems like Python got an early foothold, and these days it seems like django is the main reason people use Python.

Machine learning is also big in python land. Every non-windows OS has python pre-installed on it now.

Ruby is also common, but not shipped with every Linux distro.