Skip to content

Commit 4a5bfeb

Browse files
committed
Site updated: 2020-04-19 14:43:27
1 parent 4bd0f1d commit 4a5bfeb

3 files changed

Lines changed: 1 addition & 1 deletion

File tree

-238 Bytes
Binary file not shown.

index.html

-238 Bytes
Binary file not shown.

search.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2335,7 +2335,7 @@
23352335
<p><strong>Write tests to lock in the behaviour of your package’s API</strong><br> Test first or test later, if you shoot for 100% test coverage or are happy with less, regardless your package’s API is your contract with its users. Tests are the guarantees that those contracts are written in. Make sure you test for the behaviour that users can observe and rely on.</p>
23362336
<p><strong>If you think it’s slow, first prove it with a benchmark</strong><br> So many crimes against maintainability are committed in the name of performance. Optimisation tears down abstractions, exposes internals, and couples tightly. If you’re choosing to shoulder that cost, ensure it is done for good reason.</p>
23372337
<p><strong>Moderation is a virtue</strong><br> Use goroutines, channels, locks, interfaces, embedding, in moderation.<br>Maintainability counts</p>
2338-
<pre><code>Clarity, readability, simplicity, are all aspects of maintainability. Can the thing you worked hard to build be maintained after you’re gone? What can you do today to make it easier for those that come after you?</code></pre><p>知名 Go 语言贡献者与布道师 Dave Cheney 发表了名为《The Zen of Go》<br>编写简单、可读、可维护的 Go 代码的十个工程要点。</p>
2338+
<p>知名 Go 语言贡献者与布道师 Dave Cheney 发表了名为《The Zen of Go》<br>编写简单、可读、可维护的 Go 代码的十个工程要点。</p>
23392339
<p><strong>每个包实现单一目标</strong><br>设计良好的 Go 软件包提供一个单一的思路,以及一系列相关的行为。一个好的 Go 软件包首先需要选择一个好名字,使用电梯法则(30 秒内向客户讲清楚一个方案),仅用一个词来思考你的软件包要提供什么功能。</p>
23402340
<p><strong>明确处理错误</strong><br>健壮的程序其实是由处理故障案例的片段组成的,并且需要在故障出现之前处理好。冗余的if err != nil { return err }比出了故障再一个个去处理更有价值。panic 和 recover 也一样。</p>
23412341
<p><strong>尽早 return,不要深陷</strong><br>每次缩进时都会在程序员的堆栈中添加另一个先决条件,这会占用他们短期内存中的 7±2 个片段。避免需要深层缩进的控制流。与其深入嵌套,不如使用守卫子句将成功路径保持在左侧。</p>

0 commit comments

Comments
 (0)