<p>Hey guys, I wanted to order myself custom mug but couldn't figure what to put on it, so I thought I'd put some go code on it but don't know what would be a good snippet that would look interesting but still simple & readable.</p>
<p>I ask of you <a href="/r/golang" rel="nofollow">/r/golang</a> users to contribute your favourite pieces of code.
It can be anything from interesting designs to small short functions.</p>
<hr/>**评论:**<br/><br/>SeerUD: <pre><p>How about the standard:</p>
<pre><code>err := drinkCoffee(me)
if err != nil {
return fmt.Errorf("failed to drink coffee: %v", err)
}
</code></pre></pre>arp242: <pre><p>I think <code>drinkCoffee()</code> should be exported, as drinking coffee outside of the house is a common use case.</p></pre>shovelpost: <pre><p>Realistic example of <a href="https://youtu.be/PAAkCSZUG1c?t=13m41s" rel="nofollow">drinking returning err</a>.</p></pre>nagai: <pre><p>I'd go with a <code>panic</code></p></pre>ESBDB: <pre><p><code>
for _, sip := range mugOfCoffee {
drink(sip)
}
panic("NO MORE COFFEE!!!!!!!!!!!!!!!!")
</code></p></pre>daveddev: <pre><p><a href="https://play.golang.org/p/hQ0-bjp-oW" rel="nofollow">https://play.golang.org/p/hQ0-bjp-oW</a></p>
<pre><code>pot := make([][8]coffee, 12)
for _, cup := range pot {
me.Drink(cup)
}
</code></pre>
<p>This could be added on each iteration:</p>
<pre><code> if err := me.Urinate(); err != nil {
panic(me.Defecate(err))
}
</code></pre></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传