Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
teivah committed Sep 28, 2023
1 parent d99b4c0 commit a2d528b
Show file tree
Hide file tree
Showing 29 changed files with 562 additions and 1,552 deletions.
2 changes: 2 additions & 0 deletions docs/20-slice.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
title: Not understanding slice length and capacity (#20)
comments: true
hide:
- toc
---

# Not understanding slice length and capacity
Expand Down
2 changes: 2 additions & 0 deletions docs/28-maps-memory-leaks.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
title: Maps and memory leaks (#28)
comments: true
hide:
- toc
---

# Maps and memory leaks
Expand Down
2 changes: 2 additions & 0 deletions docs/56-concurrency-faster.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
title: Thinking concurrency is always faster (#56)
comments: true
hide:
- toc
---

# Thinking concurrency is always faster
Expand Down
2 changes: 2 additions & 0 deletions docs/89-benchmarks.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
title: Writing inaccurate benchmarks (#89)
comments: true
hide:
- toc
---

# Writing inaccurate benchmarks
Expand Down
2 changes: 2 additions & 0 deletions docs/9-generics.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
title: Being confused about when to use generics (#9)
comments: true
hide:
- toc
---

# Being confused about when to use generics
Expand Down
2 changes: 2 additions & 0 deletions docs/98-profiling-execution-tracing.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
title: Not using Go diagnostics tooling (#98)
comments: true
hide:
- toc
---

# Not using Go diagnostics tooling
Expand Down
19 changes: 12 additions & 7 deletions docs/book.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
hide:
- toc
---

# 100 Go Mistakes and How to Avoid Them

Community space of 📖 _100 Go Mistakes and How to Avoid Them_, published by Manning in 2022.
Expand Down Expand Up @@ -29,20 +34,14 @@ Read a summary of the 100 mistakes [here](https://100go.co).
Not having this will be the **101st mistake** a Go programmer could make.

<figure markdown>
![](img/ratings-manning.png)
![](img/ratings-goodreads.png){width="300"}
![](img/ratings-amazon.png){width="300"}
![](img/ratings-manning.png)
<figcaption>Manning, Goodreads, and Amazon reviews: 4.7/5 avg rating</figcaption>
</figure>

## Where to Buy?

<figure markdown>
![](img/cover-en.jpg){width="200"}
![](img/cover-jp.jpg){width="200"}
<figcaption>English and Japanese front covers</figcaption>
</figure>

* _100 Go Mistakes and How to Avoid Them_ (🇬🇧 edition: paper, digital, or audiobook)
* [Manning](https://www.manning.com/books/100-go-mistakes-and-how-to-avoid-them) (make sure to use my personal discount code for -35%: `au35har`)
* [O’Reilly](https://www.oreilly.com/library/view/100-go-mistakes/9781617299599/)
Expand All @@ -51,6 +50,12 @@ Read a summary of the 100 mistakes [here](https://100go.co).
* _Go言語100Tips 開発者にありがちな間違いへの対処法_ (🇯🇵 edition: paper or digital)
* Amazon: [.co.jp](https://www.amazon.co.jp/exec/obidos/ASIN/4295017531/)

<figure markdown>
![](img/cover-en.jpg){width="200"}
![](img/cover-jp.jpg){width="200"}
<figcaption>English and Japanese covers</figcaption>
</figure>

## About the Author

[Teiva Harsanyi](http://teivah.io) is a senior software engineer at Google. He has worked in various domains, including insurance, transportation, and safety-critical industries like air traffic management. He is passionate about Go and how to design and implement reliable systems.
2 changes: 2 additions & 0 deletions docs/chapter-1.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
title: Read the First Chapter
hide:
- toc
---

# Go: Simple to learn but hard to master
Expand Down
5 changes: 5 additions & 0 deletions docs/external.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
hide:
- toc
---

# External Resources

## English
Expand Down
1 change: 1 addition & 0 deletions docs/jobs.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
hide:
- navigation
- toc
---

# Go Jobs
Expand Down
12 changes: 6 additions & 6 deletions docs/zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ comments: true

只有在需要接受或返回任意类型时,才使用 `any`,例如 `json.Marshal`。其他情况下,因为 `any` 不提供有意义的信息,可能会导致编译时问题,如允许调用者调用方法处理任意类型数据。

### [困惑何时该用范型](https://teivah.medium.com/when-to-use-generics-in-go-36d49c1aeda) (#9)
### [困惑何时该用范型](https://100go.co/9-generics/) (#9)

使用泛型,可以通过类型参数分离具体的数据类型和行为,避免写很多重复度很高的代码。然而,不要过早地使用泛型、类型参数,只有在你看到真正需要时才使用。否则,它们会引入不必要的抽象和复杂性。

Expand Down Expand Up @@ -87,7 +87,7 @@ comments: true

在进行加法或减法时,将具有相似数量级的操作分成同一组以提高精度 (过早指数对齐丢失精度)。此外,在进行加法和减法之前,应先进行乘法和除法 (加减法误差会被乘除放大)。

### [不理解slice的长度和容量](https://teivah.medium.com/slice-length-vs-capacity-in-go-af71a754b7d8) (#20)
### [不理解slice的长度和容量](https://100go.co/20-slice/) (#20)

理解slice的长度和容量的区别,是一个Go开发者的核心知识点之一。slice的长度指的是slice已经存储的元素的数量,而容量指的是slice当前底层开辟的数组最多能容纳的元素的数量。

Expand Down Expand Up @@ -121,7 +121,7 @@ comments: true

[#21](#inefficient-slice-initialization-21).

### [map和内存泄漏](https://teivah.medium.com/maps-and-memory-leaks-in-go-a85ebe6e7e69) (#28)
### [map和内存泄漏](https://100go.co/28-maps-memory-leaks/) (#28)

一个map的buckets占用的内存只会增长,不会缩减。因此,如果它导致了一些内存占用的问题,你需要尝试不同的选项来解决,比如重新创建一个map代替原来的(原来的map会被GC掉),或者map[keyType]valueType中的valueType使用指针代替长度固定的数组或者sliceHeader来缓解过多的内存占用。

Expand Down Expand Up @@ -251,7 +251,7 @@ Wrapping(包装)错误允许您标记错误、提供额外的上下文信息

理解并发(concurrency)、并行(parallelism)之间的本质区别是Go开发人员必须要掌握的。并发是关于结构设计上的,并行是关于具体执行上的。

### [认为并发总是更快](https://teivah.medium.com/concurrency-isnt-always-faster-in-go-de325168907c) (#56)
### [认为并发总是更快](https://100go.co/56-concurrency-faster/) (#56)

要成为一名熟练的开发人员,您必须意识到并非所有场景下都是并发的方案更快。对于任务中的最小工作负载部分,对它们进行并行化处理并不一定就有明显收益或者比串行化方案更快。对串行化、并发方案进行benchmark测试,是验证假设的好办法。

Expand Down Expand Up @@ -441,7 +441,7 @@ Go 的上下文(context)也是 Go 并发编程的基石之一。上下文允

这个 `iotest` 包有助于编写 io.Reader 并测试应用程序是否能够容忍错误。

### [不正确的基准测试](https://teivah.medium.com/how-to-write-accurate-benchmarks-in-go-4266d7dd1a95) (#89)
### [不正确的基准测试](https://100go.co/89-benchmarks/) (#89)

* 不要重置或者暂停timer

Expand Down Expand Up @@ -533,7 +533,7 @@ Go 的上下文(context)也是 Go 并发编程的基石之一。上下文允

使用快速路径的内联技术来更加有效地减少调用函数的摊销时间。

### [不使用Go问题诊断工具](https://medium.com/@teivah/profiling-and-execution-tracing-in-go-a5e646970f5b) (#98)
### [不使用Go问题诊断工具](https://100go.co/98-profiling-execution-tracing/) (#98)

了解Go profilng工具、执行时tracer来辅助判断一个应用程序是否正常,以及列出需要优化的部分。

Expand Down
12 changes: 7 additions & 5 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,24 @@ theme:
- search.share
- search.suggest
- content.code.copy
- navigation.expand
- navigation.instant
- navigation.sections
palette:
# Palette toggle for light mode
- scheme: default
toggle:
icon: material/brightness-7
name: Switch to dark mode
primary: cyan
accent: pink
# Palette toggle for dark mode
- scheme: slate
toggle:
icon: material/brightness-4
name: Switch to light mode
primary: blue grey
accent: blue
repo_url: https://github.com/teivah/100-go-mistakes
plugins:
- search
Expand All @@ -41,17 +46,15 @@ extra:
provider: google
property: G-HMY1HYDM93
alternate:
- name: English
- name: 🇬🇧 English
link: /
lang: en
- name: Chinese (Simplified)
- name: 🇨🇳 Chinese (Simplified)
link: /zh/
lang: zh
social:
- icon: fontawesome/brands/twitter
link: https://twitter.com/teivah
- icon: fontawesome/brands/medium
link: http://blog.teivah.io
extra_css:
- stylesheets/extra.css
nav:
Expand All @@ -68,7 +71,6 @@ nav:
- 56-concurrency-faster.md
- 89-benchmarks.md
- 98-profiling-execution-tracing.md
- zh.md
- ❤️ Go Jobs:
- jobs.md
markdown_extensions:
Expand Down
4 changes: 4 additions & 0 deletions overrides/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
{% block htmltitle %}
<title>100 Go Mistakes</title>
{% endblock %}

{% block announce %}
This repo is open to <a href="https://hacktoberfest.com/">Hacktoberfest</a>! 🎉 If you want to participate, please have a look at the <a href="https://github.com/teivah/100-go-mistakes/issues">open issues</a>.
{% endblock %}
Loading

0 comments on commit a2d528b

Please sign in to comment.