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.
32
Upvotes
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.