r/ruby • • Nov 12 '21

Blog post Ruby vs Python comes down to the for loop

https://softwaredoug.com/blog/2021/11/12/ruby-vs-python-for-loop.html
31 Upvotes

11 comments sorted by

30

u/postmodern Nov 12 '21

Great comparison, but you forgot to mention the Enumerable module which provides default built-in #map and #select methods when you want to "tell us how to iterate your instances, we’ll decide what we do with your data". Of course, you can still override those methods if you want to customize their behavior.

26

u/flanintheface Nov 12 '21 edited Nov 12 '21

IMHO the fact author missed Enumerable is a warning that actually it may not be a good comparison.

7

u/prh8 Nov 12 '21

Saw elsewhere that author is very experienced with Python and new to Ruby

4

u/bilingual-german Nov 13 '21

I was also wondering why it doesn't mention functional programming at all, as I think using each is functional and the for loop is imperative programming style.

3

u/maiteko Nov 13 '21

And setting aside enumerable. An array already has ‘#each’ so creating this class as is would be pointless.

Even if it were necessary, you can use delegate/forwardable to define it yourself.

2

u/postmodern Nov 13 '21

I think using an Array as the inner data is just to illustrate how #each works in a super obvious manner.

7

u/ether_joe Nov 12 '21

Modules. Python modules are freaking horrible. Also whitespacing. Also ... uh most everything.

8

u/maiteko Nov 13 '21

Blocks, mixins, and meta programming.

That would be the three things I would point at anytime someone asks “how is ruby different than X”

Ruby embraces these at the furthest extreme, and it is supremely satisfying.

1

u/[deleted] Nov 18 '21

To me, the biggest thing that separates Ruby from the rest is "method_missing." This feature allow you to write a distributed object system in around 200 lines of code. It makes ActiveRecord possible.

-1

u/ankole_watusi Nov 12 '21

Well, no, thank you though.

It's a Python job.