Go中的缩进:制表符还是空格? [英] Indentation in Go: tabs or spaces?
本文介绍了Go中的缩进:制表符还是空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在某处是否有标准的Google Go编码约定文档,该文档设置了制表符或空格在Go源代码中缩进是首选?如果不是,那么(统计上)更受欢迎的选择是什么?
Is there a standard Google Go coding conventions document somewhere that sets whether tabs or spaces are preferred for indentation in Go source code? If not, what is the (statistically) more popular option?
- 官方建议是什么? (如果有)
- 更受欢迎的选择是什么?
推荐答案
官方建议使用以下格式设置代码
The official recommendation is formatting your code with
go fmt
或直接使用gofmt命令
or using the gofmt command directly
gofmt -w .
You can read more about it here on the golang.org blog, or from the Effective go document:
缩进
我们使用制表符进行缩进,并且gofmt在默认情况下会发出它们。仅在必要时使用空格。
Indentation
We use tabs for indentation and gofmt emits them by default. Use spaces only if you must.
这篇关于Go中的缩进:制表符还是空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文