PROPOSAL: fold keyword

Gabriel Belingueres belingueres at gmail.com
Tue Mar 10 11:47:45 PDT 2009


Not that it bothers me, but it is more a matter of how I could write the code:

IMHO, readability is important because code is read more times than it
is written, but written it right the first time is a goal we would
need to point to.
I mean, sugarizing some language constructions or idioms are not only
about writing less code, or that the resulting code will be more
readable, but I think the ultimate goal of sugarizing something is
(but don't know if it is the Sun's goal too):

1) it helps to preserve the "line of thought" of the programmer (that
is, not distracting him from what he wanted to do), and even better,
2) do it in a way that it reduces the probability of introducing a bug.

In this case (If we follow this criteria for a moment) creating two
static final objects, though efficient in run time and easy to read, I
see them as a distracting activity in the process of programming that
functionality. However, using a well tested library like this one
would reduce the chances of introducing bugs.

The simple for loop would certainly comply with 1) because all the
code would be there, but it would now comply with point 2) because it
does not protect us from certain kind of bugs (or side effects at
least), like using the same variable for iteration to generate and
accumulate a unique result and to hold that final result (like in the
sum example).

My goal was to find something in between.

Anyway, that were my two cents.

Best regards,
Gabriel

2009/3/10 Tim Peierls <tim at peierls.net>:
> On Tue, Mar 10, 2009 at 11:51 AM, Gabriel Belingueres
> <belingueres at gmail.com> wrote:
>>
>> I'm not specially familiar with this library, but seems like it is the
>>
>> concurrent equivalent to what can be done with the Apache Commons
>> Collections.
>
> It's a bit different from Apache Commons Collections. I think of it loosely
> as MapReduce for an in-memory array.
> The big reason to use ParallelArray is that is performs very well on
> multiprocessors without the user having to write special code to take
> advantage of parallelism. Interestingly, when I first experimented with it I
> saw a speedup of ParallelArray over equivalent sequential code on a machine
> with one hyper-threaded physical processor (2 logical processors). That
> really surprised me.
>
>>
>> Though the method call is very readable (given the
>> appropriate naming of the predicates and mapping), this need the extra
>> objects and anonymous classes I wanted to avoid creating. Not that
>> there is anything wrong with that, it is just I wanted to find a more
>> straightforward way to do it (if there is any).
>
> Simple sequential code is more straightforward, as Josh demonstrated.
> Why does creating the extra objects bother you? You're not creating those
> objects in the inner loop. One Predicate object can be used for gazillions
> of predicate tests and it takes up almost no memory.
> --tim



More information about the coin-dev mailing list