Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Why Python

Name: CrieS Raymond 2007-07-11 20:55 ID:zwAX6BRF

"[on reduce() being removed from python]So now reduce(). This is actually the one I've always hated most, because, apart from a few examples involving + or *, almost every time I see a reduce() call with a non-trivial function argument, I need to grab pen and paper to diagram what's actually being fed into that function before I understand what the reduce() is supposed to do. So in my mind, the applicability of reduce() is pretty much limited to associative operators, and in all other cases it's better to write out the accumulation loop explicitly."

ONE WORD, THE FORCED GUIDO VAN ROSSUM, THREAD OVER.

for the love of god, this guy is the dumbest programmer ever. even the most newbies programmers I know at my smalltalk class at university know how to use inject:into:, and would never write an acummulator loop correctly. Argue to any smalltalker that writing

|total|
aCollection do: [e| total := e method + total]
^total

is better and clearer than

^aCollection inject: 0 into: [e| total + e method]

and he'll kick you in the ass. And smalltalk isn't even a functional language!

Name: Anonymous 2007-07-12 21:03 ID:CSESQMtj

Actually guido wanted to remove lambda from the language, but he couldn't. I'm talking about Python 3000, which is not supposed to be backwards compatible.
Anyway, guido says he hates reduce because it's too complex and has to write in paper what is doing every time he reads it.
I must admit understanding foldl, foldr, and the difference between them, took me a while; but it's no big deal, especially if  you can use either foldl or foldr.
Either way, my programming teacher at a course on oop, functional and logic programming (yeah, it's a bit of everything and yeah, it skips a lot of important stuff), taught it in 5 minutes, and everybody in the class understood how reduce worked. It's simple. You take three arguments, a list/collection/whatever, an initial value, and a function receiving two arguments, an element of the list, and a partial total. reduce applies this function to the list, what the function returns becomes the new partial total in the next application. The initial value is the starting partial total. After reduce has applied the function to all elements, it returns the total.

Nothing amazingly complex. It's easy to what

reduce(0, function(partialTotal,x){ return x.length + partialTotal;},aListOfStrings);

does.

or, let's say:

reduce(-1, function(partialTotal, x) { return max(x, partialTotal); }, aListOfNumbers);

or simply

reduce(-1, max, aListOfNumbers);



sums all the elements of the list.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List