TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: LINQ for Go

84 pointsby aabalkanover 11 years ago

9 comments

bad_userover 11 years ago
In LINQ, the extension methods defined on IEnumerable are useful, but not that interesting, because they are standard functionality in most modern languages. I also think the naming used (e.g. Where, Select) is unfortunate and it would be better to go with the naming used by other languages&#x2F;frameworks that are much more standard, like filter() or map(). This implementation is also missing SelectMany (e.g. flatMap or bind), which is much more interesting than Select and Where (i.e. you can implement Select and Where in terms of SelectMany).<p>What makes LINQ special is IQueryable, e.g. the ability to transform a C# expression at runtime into something else, like a database query. Whenever I see article titles like &quot;LINQ in X&quot;, I somehow know that it doesn&#x27;t refer to IQueryable, which is a pity.<p>Anyway, these functions should be standard in any modern programming language and because Go is missing such standard functionality is one reason for why I don&#x27;t like Go. Lack of generics has much to do with it, but also Go&#x27;s interfaces are weaker than type-classes, combined with Google&#x27;s disregard for everything we&#x27;ve learned about type-systems in the past 30 years (behold Dart&#x27;s covariant generics) and so I do have reasons for not holding my breath waiting for a fix. Of course, Go is what many people want, so Go is what many people receive.
评论 #7010627 未加载
评论 #7010612 未加载
评论 #7011195 未加载
评论 #7011495 未加载
kmontroseover 11 years ago
Another approach using code generation is gen: <a href="http://clipperhouse.github.io/gen/" rel="nofollow">http:&#x2F;&#x2F;clipperhouse.github.io&#x2F;gen&#x2F;</a><p>(Disclaimer, I work with the guy behind it)<p>Personally these sorts of libraries just strengthen my opinion that golang really needs proper generics. However, if you&#x27;re already gonna use Go they&#x27;re pretty neat.
评论 #7010117 未加载
krakensdenover 11 years ago
From the documentation: &gt; So if you have 1M elements as input to a plinq function, you will end up 1M goroutines.<p>&gt; Theoretically, there is not much wrong with that.<p>Understatement in the finest tradition of man pages and RFCs.
评论 #7010122 未加载
overgardover 11 years ago
Neat. I guess Go can&#x27;t do type inference on the function types though? Those anonymous function signatures are all kinds of gross.
评论 #7011180 未加载
评论 #7010267 未加载
DanWaterworthover 11 years ago
yuck, I don&#x27;t understand how go people can put up without parametric polymorphism.
评论 #7010384 未加载
shadowmintover 11 years ago
Worth noting that the syntax example is slightly incorrect.<p>Since go auto-postpends ; to lines, you must have a trailing . on the line to allow the compiler to consider multiline statements like this as multiline statements instead of multiple (syntactically incorrect) single statements.<p>I presume this is just done for readability in the docs, but it&#x27;s a little misleading. Correctly, it would be:<p><pre><code> over18Names, err := From(students). &#x2F;&#x2F; &lt;--- Notice the trailing . to prevent ; Where(func (s T) (bool,error){ return s.(*Student).age &gt;= 18, nil }). Select(func (s T) (T,error){ return s.(*Student).name, nil }). Results() </code></pre> It&#x27;s argued now and then that this is one of the reasons go isn&#x27;t useful for chain expression libraries like this; it becomes hard to tell at a glance the difference between two consecutive statements and one chained long statement.<p>(The other reason typically given is it breaks error return expectations, but whatever. I&#x27;ve never really understood what&#x27;s so hard about simple having the .Final() or .Resolve() or .Results() statement at the end of a chain to get the return code and&#x2F;or error details <i>shrug</i>)
MichaelGGover 11 years ago
The real language part of LINQ isn&#x27;t the simple sequence functions (.NET had them before LINQ), it&#x27;s the LINQ monad embedded into the language.<p>While personally I don&#x27;t think I&#x27;ve ever used the LINQ monad syntax, and wish it had been implemented as a generic feature, not every language with support for anonymous functions or closures or function pointers is &quot;LINQ&quot;.
评论 #7010409 未加载
评论 #7010455 未加载
codereflectionover 11 years ago
Can&#x27;t say I&#x27;m a fan of the syntax, but nice work nonetheless.
virtualwhysover 11 years ago
Nice job but sorry, that is some hideous syntax require to make LINQ Go ;-)<p>Was expecting the concision and elegance of LINQ-to-SQL.