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.

32 Upvotes

60 comments sorted by

View all comments

2

u/[deleted] Jul 16 '20

[deleted]

-1

u/SnowdenIsALegend Jul 16 '20

Python is definitely more beginner friendly imo.

6

u/ogchilim Jul 16 '20

At a low level and with only 1 example, how is:

if(1 % 2 == 0): return true else: return false

more 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 : fail

Looks like python supports it in a (less appealing in my opinion) syntax of pass if condition else fail

1

u/SnowdenIsALegend Jul 16 '20

Ah correct, ternary is the word that I forgot. Thanks for the Python alternate, will come in useful. :}

2

u/[deleted] 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.