> For the complete documentation index, see [llms.txt](https://gocompiler.shizhz.me/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gocompiler.shizhz.me/7.-golang-bian-yi-qi-qing-chu-wu-xiao-dai-ma/7.1-jian-jie.md).

# 7.1 简介

程序中可能存在一些代码，虽然具备语义上的价值，但程序在运行时可能永远不会执行到。例如下列代码：

```go
package main

const version = 1.16 // 可能定义在某个第三方包中的常量

func main() {
    if version <= 1.15 {
        // Do something
    } else {
        // Do something else
    }
}
```

可以发现上述 if 语句只会执行 `else` 中的代码，因此 `if body` 中的代码可以完全删除。除了分支（Branch）语句，逻辑运算符也可能因为短路效应（short-circuit）而造成始终只执行部分代码，例如：

```go
package main

const version = 1.16 // 可能定义在某个第三方包中的常量

func main() {
    correctVersion := version <= 1.15 && version >= 1.14
}
```

其中第一个分量 `version <= 1.15` 为 false, 因此整个逻辑表达式的值也是 false, 没有必要再对第二个分量求值，代码 `version >= 1.14` 为无效代码。

聪明的编译器应该有能力清除掉这样的无效代码，这样可以减小最终可执行文件的大小，并且在程序执行时提升缓存命中率（增加程序的局部性，减少 Page Fault 中断的次数），从而提升程序性能。
