Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

LINQ methods are higher order functions ? LINQ syntax is just sugar and probably a design mistake (dead weight feature that I've only seen abused to implement monadic composition by insane people).

And Ruby doesn't even enter this conversation if we're talking about these kinds of optimizations - it's an order of magnitude away from what you're aiming from if you're unrolling sequence operations in C#.



> LINQ syntax is just sugar and probably a design mistake

I find that the term "LINQ" these days tend to mean the extensions on IEnumerable/IQueryable, and not the special query syntax. Whatever the term meant when it was launched is now forgotten. Almost no one uses the special query syntax, but everyone uses the enumerable/queryable extension methods like Select() etc, and calls it "Linq".


> "Whatever the term meant when it was launched is now forgotten"

Language INtegrated Query. The SQL query isn't written inside a string, opaque and uncheckable, it's part of the C# language which means the tooling can autosuggest and sanity check database table names and field names against the live database connection, it means the compiler is aware of the SQL data types without manually building a separate ORM/layer.

That people who don't use C# think it's just a Microsoft way to write a lambda filter on an in-memory list is sad.


> Almost no one uses the special query syntax

Source? I'm in multiple current, active development projects with companies, they are all using the LINQ query syntax.

Not to mention all of the legacy code out there that is under active maintenance.

To say almost no one feels very much antithetical to my (albeit anecdotal) experience. I can't imagine, I'm the only c# consultant that has multiple clients that use LINQ queries extensively throughout their applications.


Trying to crudely estimate the popularity i tried doing a regex search for C# statements ending with select ___; vs calls to Select(/Where(. It was (only) a factor 10x which was way less difference than I thought to be honest. I have seen and used one in the wild just a handful of times during 22 years of C#. But it might also vary with industry. It's likely a lot more common in fields where there are databases than where there are not.

  [1] https://github.com/search?q=%2F%28%3F-i%29%5Cs%2Bselect%5Cs%2B%5Cw%2B%3B%2F+language%3AC%23&type=code&ref=advsearch

  [2] https://github.com/search?q=%2F%28%3F-i%29%5Cs%2B%5C.%28Select%7CWhere%29%5C%28%2F+language%3AC%23&type=code&ref=advsearch


I'm actually surprised reading some of those LINQ queries, first few pages, none of them (IMO) should be using query syntax. Hell, I hate query syntax to begin with, and use the extensions any opportunity I'm allowed.

But I would also say that the companies using query syntax are also vastly underrepresented on GitHub public repositories.

> It's likely a lot more common in fields where there are databases than where there are not.

I think beyond that, it's probably more common with developers that came from doing SQL queries but "needed" type safety.

I've worked with developers that didn't even know the extension methods existed. They went from SqlCommand to LINQ to EF or LINQ to SQL.

The only time I think query syntax is better than the extension methods is when dealing with table joins.


> The only time I think query syntax is better than the extension methods is when dealing with table joins.

Fairly niche, but query syntax is a great approximation of Haskell's do notation:

https://github.com/louthy/language-ext/wiki/Thinking-Functio...

EDIT: updated URL


> but everyone uses the enumerable/queryable extension methods like Select() etc, and calls it "Linq"

Most likely because those extension methods are all under the System.Linq namespace. Really they should've gone under System.Query or something like that.


It's me, I'm insane people :) (or was in 2010?)

IIRC it was to implement a constraint solver, which I couched in monadic terms somehow, don't remember the details. Not sure if I'd do it the same way again, but I did get it to work.


If it's some small isolated part or personal project I guess it doesn't matter - but I've seen a mature codebase that was started that way - and it was among the worst codebases I've seen in 20 years (of similar scale at least).

Few people even knew how to use it or what monads were, it was a huge issue when onboarding people. When the initial masochist that inflicted this on the codebase left, and stop enforcing the madness, half of the codebase dropped it, half kept it, new people kept onboarding and squinting through it. This created huge pieces of shit glue code that was isolating the monadic crap everyone was too afraid to touch. Worst part was that even if you knew monads and were comfortable with them in other languages they just didn't fit - and it made writing the code super awkward.

Not to mention debugging that shit was a nightmare with the Result + Exceptions - worst of both worlds.

It's basically writing your own DSL by repurposing LINQ syntax - DSLs are almost always a bad idea, abusing language constructs to hack it in makes it even worse.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: