Programming in Go: Creating Applications for the 21st Century (Developer's Library)

Programming in Go: Creating Applications for the 21st Century (Developer's Library)

Mark Summerfield

Language: English

Pages: 496

ISBN: 0321774639

Format: PDF / Kindle (mobi) / ePub


Your Hands-On Guide to Go, the Revolutionary New Language Designed for Concurrency, Multicore Hardware, and Programmer Convenience

 

Today’s most exciting new programming language, Go, is designed from the ground up to help you easily leverage all the power of today’s multicore hardware. With this guide, pioneering Go programmer Mark Summerfield shows how to write code that takes full advantage of Go’s breakthrough features and idioms.

 

Both a tutorial and a language reference, Programming in Go brings together all the knowledge you need to evaluate Go, think in Go, and write high-performance software with Go. Summerfield presents multiple idiom comparisons showing exactly how Go improves upon older languages, calling special attention to Go’s key innovations. Along the way, he explains everything from the absolute basics through Go’s lock-free channel-based concurrency and its flexible and unusual duck-typing type-safe approach to object-orientation.

 

Throughout, Summerfield’s approach is thoroughly practical. Each chapter offers multiple live code examples designed to encourage experimentation and help you quickly develop mastery. Wherever possible, complete programs and packages are presented to provide realistic use cases, as well as exercises. Coverage includes

 

  • Quickly getting and installing Go, and building and running Go programs
  • Exploring Go’s syntax, features, and extensive standard library
  • Programming Boolean values, expressions, and numeric types
  • Creating, comparing, indexing, slicing, and formatting strings
  • Understanding Go’s highly efficient built-in collection types: slices and maps
  • Using Go as a procedural programming language
  • Discovering Go’s unusual and flexible approach to object orientation
  • Mastering Go’s unique, simple, and natural approach to fine-grained concurrency
  • Reading and writing binary, text, JSON, and XML files
  • Importing and using standard library packages, custom packages, and third-party packages
  • Creating, documenting, unit testing, and benchmarking custom packages

Bandit Algorithms for Website Optimization

More Than Genes: What Science Can Tell Us About Toxic Chemicals, Development, and the Risk to Our Children

The Agrarian Question in the Neoliberal Era: Primitive Accumulation and the Peasantry

How to Build a Billion Dollar App: Discover the Secrets of the Most Successful Entrepreneurs of Our Time

The Agrarian Question in the Neoliberal Era: Primitive Accumulation and the Peasantry

Windows Server 2012 Hyper-V Cookbook

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

result but scaled by unity. So in the final line (➍) we 10 reverse the scaling by dividing the result (in pi) by 10 . Using the big.Int type takes some care since most methods modify their receiver (this is done for efficiency to save creating lots of temporary big.Ints). Compare 64 Chapter 2. Booleans and Numbers the line where we perform the computation pi × left with the result being stored 10 in pi (63 ➤, ➌) to the line where we compute pi ÷ 10 and return the result (63 ➤, ➍)—not caring

literal $ in a replacement string. ★ A good textbook that teaches regexeps is Mastering Regular Expressions; see Appendix C. The author’s book, Programming in Python 3, has a chapter that teaches Python regexeps (these support a subset of regexp syntax). This chapter is available as a free download from www.informit.com/title/ 9780321680563 (click the “Sample Content” link and download Chapter 13). ✪ Information on RE2, including links to documents covering its rationale, performance, and

wordRx := regexp.MustCompile(`\w+`) if matches := wordRx.FindAllString(text, -1); matches != nil { previous := "" for _, match := range matches { if match == previous { fmt.Println("Duplicate word:", match) } previous = match 3.6. Other String-Related Packages 127 } } The regexp greedily matches one or more “word” characters. The regexp.Regexp.FindAllString() function returns a []string of all nonoverlapping matches. If there was at least one match (i.e., matches is not nil), we iterate over

(4.49) Wrench (2.99) Screwdriver (2.49)] Here we have created a slice of pointers to Products ([]*Product), and immediately initialized the slice with three *Products. This works because Go is smart enough to realize that a []*Product requires pointers to Products. What we have written is really a shorthand for products := []*Product{&Product{"Spanner", 3.99}, &Product{"Wrench", 2.49}, &Product{"Screwdriver", 1.99}}. (Recall from §4.1, 140 ➤, that we can use the &Type{} syntax to create a new

population) Mumbai's population is 12690000 Emerald City's population is 0 If we look up a key that is present in the map the corresponding value is returned. But if the key is not present then the map’s value type’s zero value is returned. So, in this example, we cannot tell whether the 0 returned for the "Emerald City" key means that the population of Emerald City really is zero, or that the city isn’t in the map. Go’s second map lookup syntax provides the solution to this problem. city :=

Download sample

Download