r/programming • • Aug 30 '08

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

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

122 comments sorted by

View all comments

Show parent comment

16

u/[deleted] Aug 31 '08 edited Aug 31 '08

His assertion that whitespace and "frost" (his term for a perceived coldness in Python culture) make Python inferior to Ruby make it hard to take his other assertions seriously.

In Python you have to enter more "self"s. In Ruby you have to enter more "end"s (rather than having whitespace interpretation figure that out for you). Neither are big deals.

12

u/shifty3 Aug 31 '08 edited Aug 31 '08

One thing about Python that annoys me are the builtin functions like len(), reduce(), map() etc. Why aren't these object methods? len() even calls __ len __(). Is this some legacy stuff?

Ruby is much more consistent in this regard, I especially like the convention of using an exclamation mark to denote destructive methods.

4

u/[deleted] Aug 31 '08 edited Aug 31 '08

At least len is a function

lambda x:len(x)
<function <lambda> at 0xb7d0ebfc>

ever been bitten by this one? I have :

lambda x:print(x)
  File "<stdin>", line 1
    lambda x:print(x)
                 ^
SyntaxError: invalid syntax 

5

u/ubernostrum Aug 31 '08

Meh. All languages have inconsistencies like this. Python's len() doesn't really bother me, personally (I like having a convenient polymorphic built-in for certain common operations), but if you see it as an abomination you don't have to use it (or Python).

1

u/Wavicle Aug 31 '08

but if you see it as an abomination you don't have to use it (or Python).

Ahh, there's the frost he was talking about.

5

u/Leonidas_from_XIV Aug 31 '08

If I'd complain about Ruby's ends and aliased names what would the Ruby community respond? "We'll remove them for you" or "You can just as well use something else"?

9

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

Um... OK. "If you don't like it, that's OK" is frost? "If you don't want to use it, you don't have to" is frost?

1

u/Niten Aug 31 '08

I'd much prefer that van Rossum constantly change the design of the language in order to suit the whims of its detractors. Clearly that's the only non-frosty option.

3

u/mikkele Aug 31 '08

No, you get that with virtually every Open Source community: "If you don't like it, then by all means don't use it, or - even better - here's the source code, so now you fix it. Otherwise STFU".

5

u/[deleted] Aug 31 '08

You get that with every discipline. It's the delineation between business and community. For some reason, some people in computing take that difference as a philosophy. If you come into my house and rant at me about my choice of wallpaper STFU would be a legitimate response. If I was wallpapering your front room in exchange for your money I'll put whatever goddamn wallpaper up you like.

Here's one we have to post every six months or so :

"We don't want our editor to have colour syntax highlighting. We will never add that functionality. We don't feel like entering into a discussion on the merits, demerits or otherwise. It's just not happening. Feel free to add it yourself, you know where the source code is."

7

u/[deleted] Aug 31 '08

All three of those functions are built-ins because they operate on any object that looks like a sequence, including lists, tuples, generators, iterators, strings, and any user-defined object that can be iterated over. 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? Wouldn't it be smarter to implement these very generic functions as something that will work on any list-like object?

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.

2

u/twotime Aug 31 '08

I agree with you on map/reduce (they utilize a low-level property of objects (iterability)).

But len() is a somewhat different beast: is not it defined as

def len(x): return x.len()

and to support len() a class must define method len()?

So why not require every object to define method len() and get rid of len() builtin?

Is there any benefit to len(x) over x.len()?

(at the very least: x.len() removes an extra level of indirection)

E.g python does not have read() builtin (which just calls read method), instead you simply define a read()method when you need it

1

u/[deleted] Aug 31 '08

Conceptually, it is just calling __len__(), although for sequence-like internal objects there is a different mechanism tried if no explicit length interface is defined. In the case of len(), I would probably prefer that it be an instance method.

Part of the reason for that is that I was wrong about len() taking iterables. If the object doesn't define __len__() and isn't a "sized" type (an internal implementation detail concerning tuples and strings), the operation fails. It doesn't "follow" iterators to count how many things they yield. So unlike map, reduce, filter, et al., it's not a generic high-level utility (even if a simple one) so much as a stub. I imagine that it is around primarily for historical reasons, and now that a __len__() interface exists, it is very hard to get rid of.

One thing I will say in its favor is that it makes sequences easier to work with in C modules since __len__() is much more clearly defined in that context than "some random instance method with a pseudo-standardized name", and the internal version of len(), called PyObject_Size(), returns a C integer instead of a PyObject*. Even if you call len() in Python against a pure-python __len__(), a TypeError is raised if the function doesn't return an integer.