News for hackers. Stuff that matters.
Re:The Wrong Aesthetic by sosorry on Sunday June 13, 2010 @03:03PM (#1427941)
I don't particularly understand what makes the second one more confusing than the first.

In particular, as a non-c programmer this: "(*i)->faceValue()" would be pretty confusing to me.

The first one in 'English':

"For each i starting at dice.begin(), while i is not equal to dice.end, incrementing i. Add to 'total' the face value of the thing that i is pointing to."

The second one in 'English': "Accumulate from dice.begin to dice.end, initializing the accumulator to 0, adding the face value of each die."

The first one might be idiomatic C++, but it doesn't seem to me that it would be idiomatic in any natural language.

(reduce #'+ (map 'list #'faceValue dice))

what is obvious depends on your background.

Re:The Wrong Aesthetic by Avshalom on Sunday June 13, 2010 @04:17PM (#1428103)
Really?

bind(std::plus(), _1, bind(&Die::faceValue, _2))

reads as "adding the face value of each die." to you? how. Because not knowing bind() or c++ I'm wondering what _1 and _2 means. More importantly why bind seems to take an operator, _#, and something, on the outside but takes only an integer and _# on the inside call. and, although the surround code might explain it, where 'Die' came from.

Unless you're just overlooking everything on that line except Die::facevalue. If you are, then why keep mentioning the 'i' in the for loop version.

Re:The Wrong Aesthetic by sosorry on Monday June 14, 2010 @10:49AM (#1429808)
Yes, really!

I do a lot more functional programming than I do imperative programming. An anonymous function in context of an accumulator is obvious to me.

The point that I maybe didn't make so well was that the second version is working in higher level constructs. The first version is doing a lot of integer and pointer manipulation, the second is summing across a collection.

The two versions might be speaking in different languages, to some extent, but that doesn't mean that one or the other is aesthetically wrong.

Re:The Wrong Aesthetic by praptak on Sunday June 13, 2010 @04:31PM (#1428140)
"I don't particularly understand what makes the second one more confusing than the first."

To understand the first one, you only need to know the basic C++ constructs. For the second one you need to know:

* the meaning of the four positional arguments to accumulate()

* the semantics of bind()

* the semantics of boost's placeholders

Even with some knowledge of the above, figuring out the nested binds takes a while.