News for hackers. Stuff that matters.
Re:System.Linq.Parallel Is Now Open Source by ultimape on Wednesday December 03, 2014 @03:35AM (#8692530)
Linq is a library that injects a whole bunch functional style operations on top of list-like objects. Technically speaking, its implementing a type-safe query (think SQL) language on top of them, but the difference is very minimal in practice.

What this does is allow for certain operations to automatically be run in parallel. If you wanted to add 1 to every element in an array, you could do that with with Linq:

    IEnumerable<int> numbers = new List<int>() { 1, 2, 3, 4, 5 };
    var newList = from num in numbers.AsParallel()
                    select (x => x+1);
    
but by adding ".asParallel()" to the chain:

    var newList = from num in numbers.AsParallel()
                    select (x => x+1);
your code is automatically run on each element in a parallel fashion and the runtime handles marshalling it all into a queue for processing... or however it does it's magic.

The MSDN document on the way it does it is quite clear: http://msdn.microsoft.com/en-us/library/dd997399(v=vs.110).a... - describing many linq operations as 'delightfully parallel'.

I personally love Linq. To me it feels like using a Functional Relational Mapping system when combined with Linq-To-SQL, and the same semantics can be used to create a reactive programming model similar to what is intended with kefir.js and Akka ( http://msdn.microsoft.com/en-us/data/gg577609.aspx )

The idea itself isn't new, Perl 6 has something like this planned for trivial cases like for (1..10) { $_ = $_ +1; }

----

I don't know the full story, but for me the significance of open sourcing this code is that it will potentially encourage forks and extensions that allow running stuff upon GPGPUs or other massively parallel architectures while still using Linq style syntax.

TL;DR: With Linq, Anything that implements iEnumerable (lists, arrays, streams, etc) can be made to automatically support all sorts of nifty transforms. The Parallel bits let many of them run in parallel quite trivially

Re:System.Linq.Parallel Is Now Open Source by mattmanser on Wednesday December 03, 2014 @05:25AM (#8692897)
I hate to be nit-picky, what you're presenting is non-idiomatic C#, I would guess you're not a C# programmer. No-one really uses the SQL-esque langugage. The simple methods reads better, are quicker to type, are clearer and are more succinct. 'p', 'q' also tends to be the de facto standard operator in lambda expressions, rather than 'x', 'y' or 'i', 'j'. And why would you use IEnumerable<int> where you used it, it makes no sense?

Your code should have read:

    var numbers = new List<int>() { 1, 2, 3, 4, 5 };
    var newList = numbers.AsParallel().Select(p => p + 1);
Re:System.Linq.Parallel Is Now Open Source by ajanuary on Wednesday December 03, 2014 @07:31AM (#8693347)
> 'p', 'q' also tends to be the de facto standard operator in lambda expressions, rather than 'x', 'y' or 'i', 'j'.

The authors of the plinq library are clearly not C# developers then. https://github.com/dotnet/corefx/search?p=1&q=select&utf8=%E...

Re:System.Linq.Parallel Is Now Open Source by chiph on Wednesday December 03, 2014 @01:25PM (#8695420)
I tend to use a letter somewhat related to the object I'm running the query against. Like 'c' for a List<Customer>.

While using i,j,k as loop variables have a long tradition behind them (from FORTRAN77, IIRC), no reason to limit myself when using Linq.

Re:System.Linq.Parallel Is Now Open Source by Infinitesimus on Wednesday December 03, 2014 @07:34AM (#8693357)
>I hate to be nit-picky

Then don't :). What you've presented is very much like saying "I don't encounter many people with your style of programming and thus, no one uses that style and you're not an actual programmer in this language".

Don't forget that there are varying styles of doing things. You use 'p'? great! Others will use foo, i, j, lalal, etc. No need to get worked up over such a minor issue and detract from the actual conversation at hand.

Re:System.Linq.Parallel Is Now Open Source by ilitirit on Wednesday December 03, 2014 @09:38AM (#8693893)
> No-one really uses the SQL-esque langugage.

Of course we do. I wrote this just the other day:

  var salesAndReturns = from sale in sales
				 join return in returns on new { StockId = sale.StockId, ClientStockId = sale.ClientStockId, SellPointId = sale.SellPointId }
					equals new { StockId = return.StockId, ClientStockId = return.ClientStockId, SellPointId = return.SellPointId } into gpu
					from subreturn in gpu.DefaultIfEmpty()
					select new
					{
						sale.ClientStockId,
						sale.StockId,
						Quantity = -sale.Quantity + (subreturn ?? new SellPointStock()).Quantity
					};

The are no rules restricting us from how we should use LINQ.
Re:System.Linq.Parallel Is Now Open Source by schrodinger on Wednesday December 03, 2014 @05:33AM (#8692922)
No one uses the sql esque language? Where do you get that idea from? I've been a c# dev for 7 years and have seen plenty. For complicate queries it's significantly more compact (and readable, in my opinion).

And using IEnumerable was probably making the point that it didn't have to be a list, it could be anything implementing that interface.

Re:System.Linq.Parallel Is Now Open Source by mattmanser on Wednesday December 03, 2014 @06:24AM (#8693083)
Ach, come on, the briefest trawl through recent SO questions and you'll see the % of DSLs has dropped to a small amount since it launched.

Downvoters be damned, they know not what they talk about. ultimape is clearly not a C# developer.

Re:System.Linq.Parallel Is Now Open Source by chton on Wednesday December 03, 2014 @07:44AM (#8693397)
I know people with 10 years experience with the language that still use the DSL for simple cases.

There is a lot of discussion about the usage of var, and ultimape's non-usage of it in his example is a personal preference, as well as making sense in an educational post.

And lastly, I think you'll find many developers, young and old alike, use x, y and z as their lambda parameters. I do too. It comes from the mathematical function origin of the syntax. In most early examples when it was introduced, and loads of educational materials now, lambda syntax is still presented akin to a mathematical formula:

x => x+1

In that context, using x makes a lot more sense than p, and has stuck around as a habit. It's a style thing, and everybody has their own style. You don't get to claim superior experience or skill based on a 2 line snippet that doesn't match your style.

And as an aside: you're not being downvoted by "the ignorant masses". You're being downvoted for being confrontational and not contributing to a conversation about the topic, which is Parallel LINQ and not coding style.

Re:System.Linq.Parallel Is Now Open Source by doodpants on Wednesday December 03, 2014 @09:56AM (#8694002)
"Ach"? "Trawl"? No one uses those words. You're clearly not an English speaker.
Re:System.Linq.Parallel Is Now Open Source by smcl on Wednesday December 03, 2014 @11:37AM (#8694658)
They're reasonably prevalent in Scotland
Re:System.Linq.Parallel Is Now Open Source by kbenson on Wednesday December 03, 2014 @12:21PM (#8694980)
Tch, come on, the briefest trawl through recent blog posts and you'll see the % of Scottish idioms has dropped to a small amount since people have been blogging. Downvoters be damned, they know not what they talk about. mattmanser is clearly not an English speaker.
Re:System.Linq.Parallel Is Now Open Source by talles on Wednesday December 03, 2014 @07:50AM (#8693418)
For simpler stuff, ya, DSL is not handy at all. But for the complex ones, shame on you if you don't DSL it. And don't come with percentage of SO questions bullshit, that's bad programmer excuse.

For longer queries, that little DSL syntax it's a bless. It's way more pleasant to read, write or think about it than the alternative.

Ah, and since you care so much about it, I've been developing in C# for freaking years that I don't bother to sum it up anymore.

Re:System.Linq.Parallel Is Now Open Source by S_A_P on Wednesday December 03, 2014 @10:30AM (#8694194)
SO is as much about making yourself look as smart as possible while still needing help. I would bet half of the folks submitting questions over linq use resharper to "nerdify" their code before they submit it...
Re:System.Linq.Parallel Is Now Open Source by darklajid on Wednesday December 03, 2014 @01:51PM (#8695606)
Not a fan of the DSL myself, but plenty of people in this C# shop here use it. Plus, replacing 'let' becomes ugly using methods rather quickly, for example.
Re:System.Linq.Parallel Is Now Open Source by recursive on Wednesday December 03, 2014 @12:25PM (#8695009)
I use the query syntax. And I have since .net 3 came out. I also use extension methods. In particular "let" can be much easier to accomplish in the query syntax. And I've usually used the first letter of the type I'm dealing with for my lambda parameters. I've never seen any standard that favored p or q.
Re:System.Linq.Parallel Is Now Open Source by nightski on Wednesday December 03, 2014 @05:33AM (#8692925)
I'd have to disagree. Sure for the simple one liner this is true. But start doing let bindings, group by, etc.. and the standard methods can get very messy.

There is nothing wrong with the DSL syntax at all.

Re:System.Linq.Parallel Is Now Open Source by guiomie on Wednesday December 03, 2014 @08:35AM (#8693617)
I prefer the non SQL-esque way also, I find it prettier, and I rarely see it at work. As for q and p, and I always use i, and I see lots of other random letters. Does the letter used really matter?
Re:System.Linq.Parallel Is Now Open Source by rikkus on Wednesday December 03, 2014 @10:44AM (#8694271)
How do you write joins? I find them readable with the SQL-esque way, but I haven't found a nice way to write them with the 'code' way.