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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Alternatives to sum types in Go

5 点作者 willsewell超过 7 年前

2 条评论

burntsushi超过 7 年前
Good post! Crossposting my comment from that other crusty news aggregator:<p>Alternative 1a is to use Alternative 1 with <a href="https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;go-sumtype" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;go-sumtype</a> &#x2F;plug<p>go-sumtype requires the interface to be sealed (which you&#x27;re already doing) and one small annotation:<p><pre><code> &#x2F;&#x2F;go-sumtype:decl TheInterfaceName </code></pre> Then you just run `go-sumtype`<p><pre><code> $ go-sumtype $(go list .&#x2F;... | grep -v vendor) </code></pre> and it will do exhaustiveness checks in any type switch in which `TheInterfaceName` participates. This will prevent the &quot;For example, during a refactor a handler might be removed but a type that implements the interface is not.&quot; failure mode mentioned in the article.
willsewell超过 7 年前
Somewhat off topic, but the idea to show the examples as diffs against the prior one was based on this block post: <a href="https:&#x2F;&#x2F;jameshfisher.com&#x2F;2017&#x2F;11&#x2F;23&#x2F;diff-views" rel="nofollow">https:&#x2F;&#x2F;jameshfisher.com&#x2F;2017&#x2F;11&#x2F;23&#x2F;diff-views</a>.<p>I would be interested to hear people&#x27;s thoughts on the effectiveness. I like how it is clear what is important in each example, but there is perhaps too much noise and it&#x27;s a shame the regular syntax highlighting does not work.