TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Closures are the Generics for Go

8 点作者 RabbitmqGuy将近 8 年前

2 条评论

saghm将近 8 年前
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 未加载
lloydjatkinson将近 8 年前
If I had to choose between no generics or "generics as closures" I'd vote no generics.