python without OO

Timo Virkkala a at a.invalid
Thu Jan 27 03:38:48 EST 2005

beliavsky at wrote:
> I think the OO way is slightly more obscure. It's obvious what x =
> reverse(x) does, but it is not clear unless you have the source code
> whether x.reverse() reverses x or if it returns a reversed list. If
> x.reverse() does the former, a disadvantage relative to the procedural
> approach is that a function can be used in an expression. It is clearer
> and more concise to write

Sure, it's clear if in written code you see

x = reverse(x)

To me it would also be clear to see


But what if you just see in some list that there is a reverse(sequence) 
function, or that a sequence has a reverse() method? To me, neither of these is 
clear. Do they return a new, reversed sequence or reverse in place?

When creating a new API, I would probably use a convention where reverse does it 
in place and reversed returns a new. So, in my API,

y = reversed(x)
y = x.reversed()

Timo Virkkala

More information about the Python-list mailing list