←back to thread

201 points olvy0 | 4 comments | | HN request time: 0s | source
Show context
olvy0 ◴[] No.41879131[source]
For me, the most useful part of LINQ is neither the IQueryable syntax tree based extension mechanism, nor the language integrated part (which I dislike), but simply the IEnumerable extensions. Originally known somewhat confusingly as linq to objects. Those allow me to write c# in functional style, keeping the code concise.

The post I submitted refers mostly to optimizations to those extension methods.

This clicked for me after having learned Haskell. It also shares some of Haskell's features/pitfalls, such as laziness.

There are pitfalls, sure, and honestly I wouldn't advise a team having no one somewhat experienced with basic functional idioms (including laziness) to use it. It can lead to obtuse and slow code if used indiscriminately. I try to lead by example myself.

replies(6): >>41879608 #>>41879713 #>>41882332 #>>41882614 #>>41883044 #>>41883519 #
jasonthorsness ◴[] No.41879713[source]
This is how I use LINQ as well. With some non-standard names, it has everything you need! Eric Lippert wrote a great series on monads tying it to LINQ:

https://ericlippert.com/2013/04/02/monads-part-twelve/

replies(1): >>41885550 #
1. karmakurtisaani ◴[] No.41885550[source]
Why on earth they named map as s Select and flatmap as SelectMany, I'll never understand. Still vert useful tho.

(I first learned FP with Scala, so the names from there feel the most natural to me, tbh)

Edit: it just occurred to me it has to be SQL inspired or something like that.

replies(2): >>41886565 #>>41893911 #
2. rjbwork ◴[] No.41886565[source]
Yeah it was intended to be easy to learn to people familiar with SQL. LINQ2SQL and Entity Framework are basically a way to query your database by constructing an abstract representation of your query using strongly typed bindings in your application code. So then the extension method syntax of it was a great way to sneak functional list programming idioms into it. Watching the proliferation of functional style in the .NET ecosystem over the past 15 years has been pretty impressive, IMO.
replies(1): >>41886867 #
3. karmakurtisaani ◴[] No.41886867[source]
Indeed, I worked in Scala for a while, dabbled with rust on my free time and am now back to writing C#. Although I prefer the two first, I have to say the ergonomics have improved significantly in C# and there are now nice options for rewriting legacy spaghetti OOP-code.
4. bazoom42 ◴[] No.41893911[source]
Map is Select and filter is Where to align with SQL keywords.