Автор: Jon Bodner
Издательство: O’Reilly Media, Inc.
Год: 2023-02-01
Страниц: 167
Язык: английский
Формат: pdf, epub (true), mobi
Размер: 10.2 MB
Go has rapidly become the preferred language for building web services. Plenty of tutorials are available to teach Go's syntax to developers with experience in other programming languages, but tutorials aren't enough. They don't teach Go's idioms, so developers end up recreating patterns that don't make sense in a Go context. This practical guide provides the essential background you need to write clear and idiomatic Go.
No matter your level of experience, you'll learn how to think like a Go developer. Author Jon Bodner introduces the design patterns experienced Go developers have adopted and explores the rationale for using them. This updated edition also shows you how Go's generics support fits into the language.
It might seem a bit weird to write a book on a boring topic, so I should explain. Go has a small feature set that is out of step with most other modern programming languages. Well-written Go programs tend to be straightforward and sometimes a bit repetitive. There’s no inheritance, no aspect-oriented programming, no function overloading, and certainly no operator overloading. There’s no pattern matching, no named parameters, no exceptions. After a decade of debate and design, generics were added, but they have limitations that aren’t present in other langauges. To the horror of many, Go has pointers. Go’s concurrency model is unlike other languages, but it’s based on ideas from the 1970s, as is the algorithm used for its garbage collector. In short, Go feels like a throwback. And that’s the point.
Boring does not mean trivial. Using Go correctly requires an understanding of how its features are intended to fit together. While you can write Go code that looks like Java or Python, you’re going to be unhappy with the result and wonder what all the fuss is about. That’s where this book comes in. It walks through the features of Go, explaining how to best use them to write idiomatic code that can grow.
This book helps you:
Write idiomatic code in Go and design a Go project
Understand the reasons behind Go's design decisions
Set up a Go development environment for a solo developer or team
Learn how and when to use reflection, unsafe, and cgo
Discover how Go's features allow the language to run efficiently
Know which Go features you should use sparingly or not at all
Use Go's tools to improve performance, optimize memory usage, and reduce garbage collection
Who Should Read This Book:
This book is targeted at developers who are looking to pick up a second (or fifth) language. The focus is on people who are new to Go. This ranges from those who don’t know anything about Go other than it has a cute mascot, to those who have already worked through a Go tutorial or even written some Go code. The focus for Learning Go isn’t just how to write programs in Go; it’s how to write Go idiomatically. More experienced Go developers can find advice on how to best use the newer features of the language. The most important thing is that the reader wants to learn how to write Go code that looks like Go.
Experience is assumed with the tools of the developer trade, such as version control (preferably Git) and IDEs. Readers should be familiar with basic computer science concepts like concurrency and abstraction, as the book explains how they work in Go. Some of the code examples are downloadable from GitHub and dozens more can be tried out online on The Go Playground. While an internet connection isn’t required, it is helpful when reviewing executable examples. Since Go is often used to build and call HTTP servers, some examples assume familiarity with basic HTTP concepts.
While most of Go’s features are found in other languages, Go makes different tradeoffs, so programs written in it have a different structure. Learning Go starts by looking at how to set up a Go development environment, and then covers variables, types, control structures, and functions. If you are tempted to skip over this material, resist the urge and take a look. It is often the details that make your Go code idiomatic. Some of what seems obvious at first glance might actually be subtly surprising when you think about it in depth.
Скачать Learning Go, 2nd Edition (Second Early Release)