diff --git a/docs/5-interface-pollution.md b/docs/5-interface-pollution.md index e4748b6..9e185b9 100644 --- a/docs/5-interface-pollution.md +++ b/docs/5-interface-pollution.md @@ -7,6 +7,8 @@ hide: # Interface pollution + + Interfaces are one of the cornerstones of the Go language when designing and structuring our code. However, like many tools or concepts, abusing them is generally not a good idea. Interface pollution is about overwhelming our code with unnecessary abstractions, making it harder to understand. It’s a common mistake made by developers coming from another language with different habits. Before delving into the topic, let’s refresh our minds about Go’s interfaces. Then, we will see when it’s appropriate to use interfaces and when it may be considered pollution. ## Concepts diff --git a/docs/92-false-sharing.md b/docs/92-false-sharing.md index 22e1f4f..3c54639 100644 --- a/docs/92-false-sharing.md +++ b/docs/92-false-sharing.md @@ -7,6 +7,8 @@ hide: # Writing concurrent code that leads to false sharing + + In previous sections, we have discussed the fundamental concepts of CPU caching. We have seen that some specific caches (typically, L1 and L2) aren’t shared among all the logical cores but are specific to a physical core. This specificity has some concrete impacts such as concurrency and the concept of false sharing, which can lead to a significant performance decrease. Let’s look at what false sharing is via an example and then see how to prevent it. In this example, we use two structs, `Input` and `Result`: diff --git a/docs/img/false-sharing.jpeg b/docs/img/false-sharing.jpeg new file mode 100644 index 0000000..3c36eff Binary files /dev/null and b/docs/img/false-sharing.jpeg differ diff --git a/docs/img/interface-pollution.jpeg b/docs/img/interface-pollution.jpeg new file mode 100644 index 0000000..39dd5fc Binary files /dev/null and b/docs/img/interface-pollution.jpeg differ diff --git a/docs/ja.md b/docs/ja.md index 9736a8c..02d98c4 100644 --- a/docs/ja.md +++ b/docs/ja.md @@ -1,6 +1,8 @@ --- title: Japanese Version comments: true +hide: +- navigation --- # Go言語でありがちな間違い diff --git a/docs/zh.md b/docs/zh.md index 3ddc139..0f3537d 100644 --- a/docs/zh.md +++ b/docs/zh.md @@ -1,10 +1,14 @@ --- title: Chinese (Simplified) Version comments: true +hide: +- navigation --- # 100个Go常见错误及如何避免 + + ## 代码及工程组织 ### 意外的变量隐藏 (#1) diff --git a/site/5-interface-pollution/index.html b/site/5-interface-pollution/index.html index dcdd2c8..e901957 100644 --- a/site/5-interface-pollution/index.html +++ b/site/5-interface-pollution/index.html @@ -1037,6 +1037,7 @@
Interfaces are one of the cornerstones of the Go language when designing and structuring our code. However, like many tools or concepts, abusing them is generally not a good idea. Interface pollution is about overwhelming our code with unnecessary abstractions, making it harder to understand. It’s a common mistake made by developers coming from another language with different habits. Before delving into the topic, let’s refresh our minds about Go’s interfaces. Then, we will see when it’s appropriate to use interfaces and when it may be considered pollution.
An interface provides a way to specify the behavior of an object. We use interfaces to create common abstractions that multiple objects can implement. What makes Go interfaces so different is that they are satisfied implicitly. There is no explicit keyword like implements to mark that an object X implements interface Y.
In previous sections, we have discussed the fundamental concepts of CPU caching. We have seen that some specific caches (typically, L1 and L2) aren’t shared among all the logical cores but are specific to a physical core. This specificity has some concrete impacts such as concurrency and the concept of false sharing, which can lead to a significant performance decrease. Let’s look at what false sharing is via an example and then see how to prevent it.
In this example, we use two structs, Input and Result:
type Input struct {
diff --git a/site/img/false-sharing.jpeg b/site/img/false-sharing.jpeg
new file mode 100644
index 0000000..3c36eff
Binary files /dev/null and b/site/img/false-sharing.jpeg differ
diff --git a/site/img/interface-pollution.jpeg b/site/img/interface-pollution.jpeg
new file mode 100644
index 0000000..39dd5fc
Binary files /dev/null and b/site/img/interface-pollution.jpeg differ
diff --git a/site/ja/index.html b/site/ja/index.html
index 18a05f3..d8f292f 100644
--- a/site/ja/index.html
+++ b/site/ja/index.html
@@ -363,7 +363,9 @@
-