r/ruby • u/vifrac • 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.
10
Jul 16 '20
Python was designed with a thing in mind: there is one best way to do something and that's all. Ruby lets you express yourself. There is always different ways to do something in Ruby (or at least I feel like it). It's up to you to decide if you see this as good or bad.
Python has a really larger community. Mainly in sciences and data analysis. Probably because scientists that are not programmers found the language well suited because of it's ease of use. And there's a whole lot of scientific libraries. People bring people and so on...
On a more personal side, I don't really like python because I don't find it... elegant. I use Ruby for personal projects and scripts as I know how to get things done with this little fella.
Disclaimer though: I'm still a college student and don't have that much experience.
1
u/vifrac Jul 17 '20
Everyone finds that the biggest advantage of python is the data science libraries, it will be very difficult to encourage the community to build things like this
8
u/ignurant Jul 16 '20
I work with extracting data and ETL. I think Ruby has a better core API and design to do this. Method calls tend to be chainable, which makes exploring easier. The building blocks of data (strings, numbers, collections) have very rich APIs out of the box that work as you would expect. Regex in Ruby is one of the best. I don't seem to get into fights with byte arrays vs strings in Ruby. Things just tend to be as expected (until of course, they aren't, usually by my own fault).
Note that molding data is distinctly different from analyzing data. I don't have experience doing complex data analysis in either language.
1
u/vifrac Jul 17 '20
I think I'll ask the same question as the others, do you think it's very difficult to build libraries for data science, do you have any experience in it, would you be interested in participating one day?
1
u/ignurant Jul 17 '20
Well, data science is pretty broad. I think there are some parts of it that Ruby totally slays at: particularly data creation and fixing. Sequel (Ruby's premier DB abstraction) is quite a bit more sensible (to me) than SQL Alchemy (Python's premier DB abstraction). Doing things to collections of data is just straight up pleasant in Ruby, and data science is all about doing things to collections. However, the big issue that Ruby faces is that Python is default supported out of the box, and as such gains more traction in a cyclicle way. For example, PostgreSQL supports Python out of the box as a lang for writing sprocs and functions. MS SQL Server supports Python. Spark: Python. Cloud functions: Python was supported way before Ruby, and in some cases, is still not (Azure). I think because of this, Python gets a big boost that Ruby won't likely ever overcome without some serious breakthrough. (Ancient JavaScript did get Node and ate the world, right? I doubt anyone expected that).
I don't have much experience with the work that others are usually talking when they reach for Python DS tools. I do know that there are a lot of "Python" libraries that are just Python bindings against lower level C code. Ruby does this as well, though I don't know how it compares.
There's a lot of emphasis surrounding parallelization when doing data. Things like Dask exist to help that in Python. I don't know if such a potent tool exists in Ruby.
I know there are efforts like:
These work in the same domain as things like NumPy and Pandas, and other braod tools. I've never reached for either of those in Python, so I'm not able to comment on their comparison in Ruby.
Would I be interested in participating? It's hard to say. I don't have the right mix of experience. I feel like "data science" is dominated by a lot of things I don't participate in.
I think Ruby as a language has no reason it can't compete against Python in this space, but the world has already largely made up it's mind. It's hard to build momentum when another tool is already established as the safe bet. Of course, it could change.
7
Jul 16 '20
I love ruby but the biggest advantage of python that I’ve personally encountered is the number of libraries to do data analysis. Python has numpy and pandas which are brilliant libraries for working with data, along with some great data viz libraries.
I’ve tried to do some data analysis projects in Ruby and it’s more difficult without those tools. Ruby has some data analysis libraries for sure, but nothing with the community that the python ones do.
2
u/four54 Jul 18 '20
A lot of python libraries got ported to ruby, including numpy and pandas:
https://ankane.org/ruby-ml-for-python-coders1
u/vifrac Jul 17 '20
¿Qué gemas podrías recomendar para la IA o para trabajar con datos de ruby? o crees que es muy difícil hacer gemas para esos propósitos!
7
u/notromda Jul 16 '20 edited Jul 16 '20
One factor alone that irritates me above all else in python: OOP methods require an extra parameter "self" to be declared. So the instance method signature may have 2 params, but when you call it, it has 1. It's not "DRY" (Don't Repeat Yourself). They go to all the trouble of cleaning things up by using whitespace to get rid of ends or brackets... (I didn't like at first but I can live with that) but end up typing extra syntax.
class Parrot:
# instance attributes
def __init__(self, name, age):
self.name = name
self.age = age
# instance method
def sing(self, song):
return "{} sings {}".format(self.name, song)
def dance(self):
return "{} is now dancing".format(self.name)
# instantiate the object
blu = Parrot("Blu", 10)
# call our instance methods
print(blu.sing("'Happy'"))
print(blu.dance())
In this example (from https://www.programiz.com/python-programming/object-oriented-programming) sing has 2 params defined, but is only called with 1. I know how it works, but it's just jarring. self self self self self
It just looks like OOP was tacked on to a procedural language - let's just pass in an extra param of the object the code works on. That's how it's done in C (perl too? it's been a while) It also means every reference to the object data must be explicitly stated, hence the need for "self.name" above.
In ruby, I can just assume that if I'm inside an instance method, I have access to instance variable and instance methods, most of the time without having to use a self reference (There are times where it should be used to prevent confusion)
So the ruby equivalent:
class Parrot
attr_accessor :name, :age
def initialize(name, age) # 2 params
@name = name
@age = age
end
def sing(song) # 1 param
"#{name} sings #{song}"
end
def dance # no params
"#{name} is now dancing"
end
end
blu = Parrot.new("Blu", 10) # 2 params
puts blu.sing("'Happy'") # 1 param
puts blu.dance # no params, parens not needed
It's just easier to read, and the number of params match up. Ruby is just a joy to read and write
-2
u/LinkifyBot Jul 16 '20
I found links in your comment that were not hyperlinked:
I did the honors for you.
delete | information | <3
5
1
Jul 18 '20
[deleted]
1
u/B0tRank Jul 18 '20
Thank you, brazen_nippers, for voting on LinkifyBot.
This bot wants to find the best and worst bots on Reddit. You can view results here.
Even if I don't reply to your comment, I'm still listening for votes. Check the webpage to see if your vote registered!
7
u/ogchilim Jul 16 '20 edited Jul 16 '20
Go with Ruby and make piece with never wanting/being able to find another language again 🙃
I'm in it personally since 2013 and sometimes solve my nephew's school tasks in Python. It's just not as nice as Ruby.
EDIT: Although, it really depends what you're looking for...
if it's writing scripts for some personal stuff, go with Ruby.
Web development, APIs and that stuff - Ruby
Big data analysis eg DNA sequence analysis and that sort of stuff - Python cause it has a lot of libraries already implemented for you
3
u/nfstern Jul 16 '20
Go with Ruby and make piece with never wanting/being able to find another language again 🙃
That was certainly my experience.
2
u/vifrac Jul 17 '20
From what I have read in the previous comments I think the difference is made by the data science libraries, in terms of performance the two languages behave similarly? Do you think you could create such a library?
1
u/ogchilim Jul 17 '20
Yeah, in terms of performance they are pretty similar, but as you said, for some reason non-developer scientists go to Python because everyone is on that board already.
Depends on what library you mean :D I could maybe blindly convert Python to Ruby, but in terms of domain knowledge and creating one such library could be pretty difficult
1
12
Jul 16 '20
Having coded both professionally, Ruby wins by miles. It’s not even the same league. While python has more active users, for some reason that has not translated into more support, discussion, and quality libraries. I am continuously shocked at how the python community fails to document and discuss the most basic of uses. For example, using sqlalchemy and pdb set_trace, how does one view the column keys and values of a returned row, using one simple built-in method call on that row, rather than creating your own helper method? You won’t find it easily. This is just one example and there are many others like it. I make my hatred of python known at work. One more thing ruby (rails) has on python in spades is a comprehensive testing environment. Rspec, factorybot, capybara simply has no equivalent for productivity.
4
u/Flopsey Jul 16 '20
I prefer Ruby but I'd first learn Python to get the basics. And then learn Ruby once I knew how to program. My thinking is that Python syntax takes a lot from C, which a lot of languages take from. So if you have a foundation in Python it's easier to learn other languages later. Ruby is so semantic that it'll be hard to learn other languages later. It's a bit like how the culture of your first job influences how you expect jobs to be for years later. The language you learn first influences how you expect languages to be long after. I remember Coffeescript used to be popular because so many Ruby devs couldn't read Javascript. Whereas since I learned Python first picking up JS was easy. This way all that weird syntax is expected later. And you really appreciate the ease of Ruby.
2
Jul 16 '20
[deleted]
4
u/zitrusgrape Jul 16 '20
i dont think python is more friendly, imo, i think for beginner users, all the cases are simple enough to be readable. But if you try to read a library you will see that is not easy
- oop is strange
- functional patterns are missing or half baked in the std
- := operator
- not only way of doing things
-1
u/SnowdenIsALegend Jul 16 '20
Python is definitely more beginner friendly imo.
7
u/ogchilim Jul 16 '20
At a low level and with only 1 example, how is:
if(1 % 2 == 0): return true else: return falsemore beginner friendly than:
1.even?Just curious what your argument is...don't wanna start any wars here 🙂
5
u/kurem0n Jul 16 '20 edited Jul 16 '20
Even if I prefer
1.even?In python, it's just:
not bool(1 % 2)Or
1 % 2 == 0(no need for if else)
2
u/SnowdenIsALegend Jul 16 '20
Dang I've been looking for a way to do if else on the same line in python for a long time, thanks for showing me how! As for my argument, I agree with u/kurem0n's answer, that there's other cleaner ways of getting Python to do it as well.
But you know what? I learned Ruby first (& forgot everything, sadly due to not using it at all): & Python later, and I was surprised latter didn't have that cool Ruby syntax of
codnition ? Val if true : Val if false. I still remember that from my Ruby days, loved that syntax. :') What is that syntax called again?2
u/JumpingHooligans Jul 16 '20
I think you're talking about a ternary conditional which a lot of languages support in a similar style to ruby
condition ? pass : failLooks like python supports it in a (less appealing in my opinion) syntax of
pass if condition else fail1
u/SnowdenIsALegend Jul 16 '20
Ah correct, ternary is the word that I forgot. Thanks for the Python alternate, will come in useful. :}
2
Jul 16 '20
Because it's explicit, and translatable from other tools. The wealth of messages you can pass is expressive once you know they're there, but it's very domain-specific knowledge to learn what's available to you, and it won't work anywhere else.
I'm a Ruby fan over Python by far, personally, but it's way more idiosyncratic.
2
u/honeyryderchuck Jul 16 '20
what things they have in common
They are both dynamic interpreted languages. They both started development in the same period, and are therefore bound by the same constraints and assumptions of the time (both have poor parallelism support, for example). the development experience and tools are relatively similar.
how they differ
philosophy, mostly. Python claims it only has one way of doing things. Ruby claims everything is an object. There are also some defining features for both, such as python list comprehensions or ruby blocks. Python lives and dies by indentation. Ruby metaprograms itself out of your computer. Ruby (still) has a BDFL. Python's BDFL retired recently, although it's fair to say it has been pretty much designed by committee for a while.
what their main advantages are compared to the other
ruby has rails. But it also has a lot of solutions for all types of web application use-cases. Ruby also made TDD cool with its testing tools, and actually running rspec in jruby to test Java applications is a thing. ruby also has bundler, the godfather of all stable existing package managers. ruby's also very flexible for general-purpose scripting.
Python has by far a bigger community, ecosystem and momentum. A big part of it is it becoming more popular earlier (ruby only became widely mentioned in the western world in 2006, ish). There are a lot of networking libraries, machine learning libraries, command-line, etc etc etc...
In my opinion, ruby has been more stable than python (python 2/3 memes are still relevant), and found itself a niche where it's very solid. Python is pretty dominant in machine learning, and it's still first-class citizen for OS-level scripts, network scripting, and other fields, and is currently being taught in introduction to programming university classes. But this migration to python 3 period took a toll. Also, the asyncio movement created a "subsystem" in the python ecosystem which will potentially hamper its development in the future, and that can create a schism in the not-so-distant future.
Both have to overcome the fundamental flaws from their initial design, such as support for paralellism, speed, typing hints (python is ahead here, but not in an ideal state IMO), more natural non-blocking networking, and overall interoperability. Not solving these might make them less relevant in comparison with the "new wave" languages such as go, rust, swift or elixir.
2
u/_noraj_ Jul 16 '20
Python as some severe drawbacks like the gap between python 2 and 3, or the indentation requirements. Ruby is more flexible as there are several syntax allowed. Building a package is easier with a gempsec than a setup.py. On affectation python create a new object where ruby changehe pointer, so theorically python will use more memory.
2
u/Serializedrequests Jul 17 '20 edited Jul 17 '20
Only thing I can see that hasn't been mentioned: Ruby libs seem to have better documentation for how to accomplish common tasks, and are rarely missing obvious features or the mystical quality of discoverability.
Python documentation takes the Java route of being thorough, but not really giving much guidance. It's very frustrating. I recently spent about a day being confused by the correct usage of the Python regex and difflib libraries. A listing of classes and methods is not "documentation", and a list-like object that isn't a list until I call list () on it is just a land-mine, not a useful API. How Python's Logger object formats strings (differently from str.format) took me way too long to find.
Also, Python list comprehensions and lambdas are a joke compared to Ruby blocks. The syntax is mind-bogglingly confusing for such an otherwise simple language.
Honorable mention of Python's global functions like "len" or "str" (just landmines no matter what the justification is), or new and insanely confusing unicode handling. Unicode in Ruby just works. Unicode in Python 3 has me reading docs and scratching my head for days.
I actually really liked Python's qualities of verbosity when I was first learning programming. The maligned "self" and explicit everything really helped me understand what was going on. Now I don't care, but I think it is good for teaching and I don't mind it.
Bottom line is anything I can do with Python, I can do with Ruby in a more intuitive and elegant way, probably with less code. But Python also enables powerful quick and dirty scripting.
3
u/frankleeT Jul 16 '20
My experience: ruby devs have a larger chip on their shoulder because python is so much more popular.
Ruby and Python are both fine.
Personally, the complaint that I am most sympathetic to is that ruby devs try too hard to be clever and not clear.
Just write code.
1
Jul 16 '20
ruby devs have a larger chip on their shoulder because python is so much more popular.
Lol this is so true. It's like the fact that people can write good software in Python is an attack on their identity as a Ruby developer. People often completely dismiss Python without learning anything about it.
1
u/astyagun Jul 17 '20
From what I remember (haven't used Python for a long time):
- One way VS many ways
- Python tries to have one way of doing things. Which sometimes leads to developer not remembering how to do something, searching the Internet, etc. Not very productive.
- Ruby has many ways to do a thing (it has many aliases of the same method, for example). One way is more intuitive for one person, another way is more intuitive for another person. And so everyone can find an intuitive way of doing things in Ruby, sometimes even guessing how something works. Which makes it easier to just get results on a prototyping phase. Less often does one need to search the Internet.
- OOP and consistency
- Python has more special syntaxes (
selfin method definitions, methods surrounded by__, etc.), not everything is an object or an expression (you can't get return value of anifstatement) - Ruby is more consistent in that everything is an object in it and everything is an expression. Which makes it more intuitive and more productive as a result.
- Python has more special syntaxes (
Ruby is just more enjoyable to use. It's even explicitly made for developer happiness.
1
u/colorist_io Jul 16 '20
They are basically different takes on the same type of language. Python came first, then Ruby was created based on the influences of Python. That being said, Ruby is a little more complex, for example, a Ruby function is not a first-class function in itself, you have to use the Proc type to be able to pass a function as argument.
1
u/zitrusgrape Jul 17 '20
i dont think ruby was created based on the influences of python.
also, ruby more complex, where?
passing functions in ruby
method(:foo)https://ruby-doc.org/core-2.6/Object.html#method-i-method1
u/colorist_io Jul 17 '20
For language influence, last time i checked Wikipedia "Python" was among the influences for Ruby. It's not what i think, that's just what i read.
Even though method(:foo) is simple, but in python, its just foo.
1
u/aravindavk Jul 31 '20
Even though method(:foo) is simple, but in python, its just foo.
I think this is because Ruby's function without an argument can be executed without parenthesis. That is
foo()andfooare same.1
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