Ruby vs Python comes down to the for loop  ↦

Doug Turnbull breaks down a major difference between two beloved programming languages in how they handle iteration.

Python embraces for. Objects tell for how to work with them, and the for loop’s body processes what’s given back by the object. Ruby does the opposite. In Ruby, for itself (via each) is a method of the Object. The caller passes the body of the for loop to this method.

He goes on to give examples and explain why each approach might map to different developers’ brains… differently. Here’s a succinct summary, if you don’t have time for the deeper discussion:

In Ruby, the objects control the affordances. In Python, the language does.


Sign in or Join to comment or subscribe

0:00 / 0:00