Small design details I like in Go
Go101 edited this page Sep 23, 2020
·
8 revisions
- Go supports using
aValue.Method
as a function value without losing theaValue
context. This is a so natural feature but I find that no other popular static languages support it and even some dynamic languages don't support it well. - Go supports declaring methods for any kinds of types
- Go supports using different import names to distinguish same-name imported packages.
- Except rare dot import style uses, Go forces using
pkg.
prefix to reference resources from imported packages. - Many operations on nil values don't cause panics.
-
Many variations of
for
loops. -
The position of the
default
branch in aswitch
orselect
code block can be arbitrary. - Go supports declaring types in function bodies.
- Go supports nesting function bodies in function bodies.
- The type deduction rule for the left untyped operand of a bit-shift operation depends on whether or not the right operand is a constant.
- In some scenarios, it is ok to use array pointers as arrays.
- Go disallows cyclic imports.
-
v++
andv--
can only be used as statements. - non-boolean values can't be used as booleans.
Please follow the official Twitter account of Go 101, @go100and1, to learn some Go details, facts, tips, etc, and read some Go articles from time to time.
Go 101 is a series of books about Go programming.
Books in Go 101 series
- Go (Fundamentals) 101 focuses on Go syntax/semantics (except custom generics related) and all kinds of runtime related things.
- Go Optimizations 101 provides some code performance optimization tricks, tips, and suggestions.
- Go Details & Tips 101 collects many details and provides several tips in Go programming.
- Go Generics 101 explains Go custom generics in detail.
Tapir started writing the Go 101 books and maintaining the go101.org website since 2016. New contents will continue being added to the books and the website from time to time. If you would like to, you can also support Go 101 by playing Tapir's games (for both Android and iPhone/iPad):
- Color Infection (★★★★★) - a physics based casual puzzle original game. 140+ levels.
- Rectangle Pushers (★★★★★) - a casual puzzle original game. 104+ levels.
- Let's Play With Particles - a casual action original game. Three game modes are included.