Movatterモバイル変換


[0]ホーム

URL:


styleguide

Go Style

https://google.github.io/styleguide/go

Overview |Guide |Decisions |Best practices

About

The Go Style Guide and accompanying documents codify the current best approachesfor writing readable and idiomatic Go. Adherence to the Style Guide is notintended to be absolute, and these documents will never be exhaustive. Ourintention is to minimize the guesswork of writing readable Go so that newcomersto the language can avoid common mistakes. The Style Guide also serves to unifythe style guidance given by anyone reviewing Go code at Google.

DocumentLinkPrimary AudienceNormativeCanonical
Style Guidehttps://google.github.io/styleguide/go/guideEveryoneYesYes
Style Decisionshttps://google.github.io/styleguide/go/decisionsReadability MentorsYesNo
Best Practiceshttps://google.github.io/styleguide/go/best-practicesAnyone interestedNoNo

Documents

  1. TheStyle Guide outlinesthe foundation of Go style at Google. This document is definitive and isused as the basis for the recommendations in Style Decisions and BestPractices.

  2. Style Decisions is amore verbose document that summarizes decisions on specific style points anddiscusses the reasoning behind the decisions where appropriate.

    These decisions may occasionally change based on new data, new languagefeatures, new libraries, or emerging patterns, but it is not expected thatindividual Go programmers at Google should keep up-to-date with thisdocument.

  3. Best Practicesdocuments some of the patterns that have evolved over time that solve commonproblems, read well, and are robust to code maintenance needs.

    These best practices are not canonical, but Go programmers at Google areencouraged to use them where possible to keep the codebase uniform andconsistent.

These documents intend to:

These documents donot intend to:

There will always be differences from one Go programmer to another and from oneteam’s codebase to another. However, it is in the best interest of Google andAlphabet that our codebase be as consistent as possible. (Seeguide for more on consistency.) To that end, feel free tomake style improvements as you see fit, but you do not need to nit-pick everyviolation of the Style Guide that you find. In particular, these documents maychange over time, and that is no reason to cause extra churn in existingcodebases; it suffices to write new code using the latest best practices andaddress nearby issues over time.

It is important to recognize that issues of style are inherently personal andthat there are always inherent trade-offs. Much of the guidance in thesedocuments is subjective, but just like withgofmt, there is significant valuein the uniformity they provide. As such, style recommendations will not bechanged without due discourse, Go programmers at Google are encouraged to followthe style guide even where they might disagree.

Definitions

The following words, which are used throughout the style documents, are definedbelow:

Additional references

This guide assumes the reader is familiar withEffective Go, as it provides acommon baseline for Go code across the entire Go community.

Below are some additional resources for those looking to self-educate about Gostyle and for reviewers looking to provide further linkable context in theirreviews. Participants in the Go readability process are not expected to befamiliar with these resources, but they may arise as context in readabilityreviews.

External References

Relevant Testing-on-the-Toilet articles

Additional External Writings

This site is open source.Improve this page.

[8]ページ先頭

©2009-2025 Movatter.jp