Learn Go
Nathan Youngman
  • MEAP began October 2015
  • Publication in Summer 2017 (estimated)
  • ISBN 9781617293092
  • 300 pages (estimated)
  • printed in black & white

Learn Go is a beginner's guide to the Go programming language, aimed squarely at hobbyists and new developers. It's chock-full of exercises that you can tackle with nothing more than a web browser. Move forward each day with succinctly written chapters punctuated by elaborate challenges. By the end you will have cracked ancient ciphers, discovered the wonders of cellular automatons, planned a vacation on Mars, and directed rovers to gather weather data. This is just the beginning. What you build next is up to you.

Table of Contents detailed table of contents

Preface

About this book

Roadmap
Code conventions and downloads
Author Online
About the author

Part 1: Imperative programming

1. Get ready, get set, Go

1.1 What is Go?

1.2 The Go Playground

1.3 Packages and functions

1.4 Summary

2. A glorified calculator

2.1 Performing calculations

2.2 Formatted print

2.3 Constants and variables

2.4 Think of a number

2.5 Taking a shortcut

2.5.1 Declare multiple variables at once

2.5.2 Increment and assignment operators

2.6 Summary

3. Loops and branches

3.1 True or false

3.2 Comparisons

3.3 Branching with if

3.4 Logical operators

3.5 Branching with switch

3.6 Repetition with loops

3.7 Summary

4. Variable scope

4.1 Looking into scope

4.2 Short declaration

4.3 Narrow scope, wide scope

4.4 Summary

Challenge 1: ticket to Mars

Part 2: Types

5. Real numbers

5.1 Declaring floating point variables

5.1.1 Single precision floating point numbers

5.1.2 The zero value

5.2 Displaying floating point types

5.3 Floating point accuracy

5.4 Comparing floating point numbers

5.5 Summary

6. Whole numbers

6.1 Declaring integer variables

6.1.1 Integer types for every occasion

6.1.2 Knowing your type

6.2 The uint8 type for 8-bit colors

6.3 Integers wrap around

6.3.1 Look at the bits

6.3.2 Avoid wrapping around time

6.4 Summary

7. Big numbers

7.1 Hitting the ceiling

7.2 The big package

7.3 Constants of unusual size

7.4 Summary

8. Multilingual text

8.1 Declaring string variables

8.2 Characters, code points, runes, and bytes

8.3 Pulling the strings

8.4 Manipulating characters with Caesar cipher

8.4.1 A modern variant

8.5 Decoding strings into runes

8.6 Summary

9. Converting between types

9.1 Types don't mix

9.2 Numeric type conversions

9.3 Convert types with caution

9.4 String conversions

9.5 Converting Boolean values

9.6 Declaring new types

9.7 Summary

Challenge 2: the Vigenère cipher

Part 3: Building blocks

10. Functions

10.1 Function declarations

10.2 Writing a function

10.3 Summary

11. First-class functions

11.1 Assigning functions to variables

11.2 Passing functions to other functions

11.3 Declaring function types

11.4 Closures and anonymous functions

11.5 Summary

12. Methods

12.1 Bring your own types

12.2 Adding behavior to types with methods

12.3 Summary

Challenge 3: to be determined

Part 4: Collections

13. Arrayed in splendor

13.1 Declaring arrays and accessing their elements

13.2 Don't go out of bounds

13.3 Initialize arrays with composite literals

13.4 Iterating through arrays

13.5 Arrays are copied

13.6 Multi-dimensional arrays

13.7 Summary

14. Slices: a window into an array

14.1 Slicing an array

14.1.1 Default indices for slicing

14.2 Composite literals for slices

14.3 The power of slices

14.4 Slices with methods

14.5 Summary

15. A bigger slice

15.1 The append function

15.2 Length and capacity

15.3 Investigating the append function

15.4 Three-index slicing

15.5 Preallocate slices with make

15.6 Declaring variadic functions

15.7 Summary

16. The ever versatile map

16.1 Declaring a map

16.2 Maps are not copied

16.3 Preallocate maps with make

16.4 Using maps to count things

16.5 Grouping data with maps and slices

16.6 Repurposing maps as sets

16.7 Summary

Challenge 4: a slice of life

C4.1 A new universe
C4.2 Looking at the universe
C4.3 Seeding live cells
C4.4 Implementing the game rules
C4.4.1 Dead or alive?
C4.4.2 Counting neighbors
C4.4.3 The game logic
C4.5 Parallel universe

Part 5: State and behavior

17. A little structure

17.1 Declaring a structure

17.2 Reusing structures with types

17.3 Initialize structures with composite literals

17.4 Structures are copied

17.5 Encoding structures to JSON

17.6 Customizing JSON with struct tags

17.7 Summary

18. Go's got no class

18.1 Attaching methods to structures

18.2 Constructor functions

18.3 The class alternative

18.4 Summary

19. Composition and forwarding

19.1 Composing structures

19.2 Forwarding methods

19.3 Name collisions

19.4 Summary

20. Interfaces

20.1 The interface type

20.2 Discovering the interface

20.3 Satisfying interfaces

20.4 Keep interfaces small

20.5 Summary

Challenge 5: to be determined

Part 6: Down the gopher hole

21. Pointers

22. Nil

23. Handling errors

24. Concurrency

25. Writing and consuming packages

Where to Go from here

Appendixes

Appendix A: Answers

Appendix B: Beyond the playground

About the Technology

Are you unsatisfied by the dichotomy between happiness-optimized scripting languages and high performance workhorse languages? Created at Google, Go is designed by and for working programmers who care about performance, reliability, and the experience of writing software. With its restrained and well considered design, Go is approachable to newcomers and refreshing for seasoned polyglots. With Go, you have the tools you need for rapidly building web, cloud, and systems applications. Best of all, it doesn't take long to become productive in Go. Are your ready?

What's inside

  • Broad coverage of Go syntax and features
  • A dip into the expansive standard library
  • Object-oriented design without objects or class
  • The nitty-gritty of memory management

About the reader

This book assumes you are familiar with a high-level scripting language such as JavaScript, Lua, PHP, Perl, Python, or Ruby.

About the author

Nathan Youngman is a contributor to Go's open source ecosystem and organizer of the Edmonton Go meetup.

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
Buy
MEAP combo $34.99 pBook + eBook
MEAP eBook $27.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks