by axod · 16y ago · 0 comments
var developerNames = employees.AsParallel().AsOrdered()
.Where(e => e.Role == Role.Developer)
.OrderBy(e => e.LastName)
.Select(e => e.FullName)
.ToArray();
That's just gross IMHO. AsParallel() yuck. AsOrdered() eugh why are these functions being used to set parameters.In the above example, the state of employees is the same after the execution of the statement as it was before, if you were to set the "Parallel" flag or "Ordered" flag before hand each as their own assignment statement, then you would have modified the initial object and created a side effect.
I am not challenging your opinion, but simply answering your question as to why.
var developerNames = from emp in employees.AsParallel().AsOrdered()
where emp.Role == Role.Developer
orderby emp.LastName
select emp.FullName; employees.AsParallel().AsOrdered()
to the more-traditional-C-style MaintainOrder(Parallelize(employees))
or the admittedly more attractive (maintain-order (parallelize employees))
and suddenly it seems perfectly sensible. I thought it was ugly first, too, but now I'm used to it. (maintain-order (parallelize employees))
vs MaintainOrder(Parallelize(employees))
"admittedly more attractive"?
I enjoy functional constructs, but now you're just talking syntax right? (->> employees parallelize maintain-order)
might be said to be more attractive because it looks more linear. The sequential order of application is thus maintained, and the parentheses which are perceived as additional levels of hierarchy are removed.Of course, the dot-dot-dot style in Java/C#/etc is doing the same:
employees.Parallelize().MaintainOrder()
is also linear, the parentheses are only used to specify parameters. someFunction.Memoize();
That's perfectly natural, right? (I mean, you could claim that "is memoized or not" should be a "flag" on a function, but that's starting to sound a little silly to my ears.) It's exactly analogous.On what kinds of back-end do LINQ and PLINQ support parallelization?
PLINQ is just a parallel implementation of LINQ-to-Objects and LINQ-to-XML. It works in the same scenarios .Net programs work in, i.e. multicores or SMPs running Windows (not sure if PLINQ works with Mono).