r/programming • • Aug 30 '08

Tour De Babel -- Rant about programming languages (at Amazon)

http://steve.yegge.googlepages.com/tour-de-babel
11 Upvotes

122 comments sorted by

View all comments

Show parent comment

9

u/akdas Aug 31 '08

If I want to write a list-like object without inheriting from list, should I have to write stub map/reduce/len methods just in case someone wants to use them?

In Ruby, you don't have to inherit from Array to get a bunch of methods that operate on list-like objects for free by simply includeing the Enumerable module.

Wouldn't it be smarter to implement these very generic functions as something that will work on any list-like object?

Like Ruby's Enumerable.

I like Python, and I understand it has a different philosophy, but examples like this are why I prefer Ruby (once again, it's purely a personal preference).

Now if only Ruby's built-in file manipulation libraries were better.

5

u/ubernostrum Aug 31 '08 edited Aug 31 '08

Well.

From the Python perspective I like the fact that len() is a built-in that delegates to a double-underscore method. I like the fact that a lot of other functionality works that way, too, because it means I don't have to treat a bunch of otherwise-usable public identifiers as reserved because someone might interpret their presence as meaning that I'm implementing some API.

I also like the fact that Python deliberately sets off the names of the "special" methods so you know something different is going on.

And there's a certain sparseness that results from the Python approach which appeals to me; for example, Ruby's Enumerable includes at least four methods which simply consist of "return all the items in the collection which match/don't match some condition". As a Python programmer, I instinctively ask:

  • Why should I need to tie up so many names in my class just to do one thing, when filter() or a list comprehension would do just as well?
  • Why should I have to remember which methods take which arguments (some take regular expressions, some take blocks...) instead of having a unified interface that can behave intelligently?

Similarly, there are at least three methods in Enumerable which basically boil down to "execute this code once for each item"; again, why tie up so many names when I could just use map() or a comprehension? Why have multiple methods instead of a unified interface?

1

u/shifty3 Aug 31 '08

What he said.

I'm not that much of a Python programmer, but shouldn't the same solution be possible in Python? As far as I know, it also supports mixins.

1

u/Leonidas_from_XIV Aug 31 '08

It supports mixins via Multiple Inheritance which has become somehow rare in todays OOP languages. I'm not really sure why exactly it has been considered evil.