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.

Closures are the Generics for Go

8 pointsby RabbitmqGuyalmost 8 years ago

2 comments

saghmalmost 8 years ago
It's interesting that they cite DRY as one of the reasons for refactoring the code to use closures, as it appears that in their later example of sorting, the two lambdas they pass for sorting ints and strings are identical other than type. Interestingly, it looks like that repetition could be solved by a macro that generates the function given a type. I'm not surprised super familiar with Go; I'm guessing that it doesn't have any sort of macro system that could do this, or else they would have mentioned it?
评论 #14590241 未加载
lloydjatkinsonalmost 8 years ago
If I had to choose between no generics or "generics as closures" I'd vote no generics.