BT

Go in Action - Review and Q&A with the Author

| Posted by Sergio De Simone Follow 14 Followers on Dec 04, 2015. Estimated reading time: 8 minutes |

Go in Action is a new book from Manning that aims to provide a comprehensive introduction to Go, both its syntax and implementation, and its most common idioms. InfoQ has spoken with William Kennedy, author of the book.

As usual with Manning’s “In Action” series, Go in Action is a svelte book packed with first-hand information and many insights into the language. The book, according to the authors, targets the intermediate developer with some programming experience and no previous knowledge about Go.

Thus, the book’s authors are keen on providing very clear and detailed explanations about each concept that is introduced to make sure readers have the necessary information to understand it fully. A great example of this is the discussion about Go’s built-in data types – arrays, slices, and maps – where you will not only learn how to use them, but also how they are conceptually implemented and how they behave in typical situations, e.g. when growing a slice or when taking a slice of a slice. For more experienced Go developers, this book can also be appealing, mostly thanks to the final chapters, which cover advanced topics such as common concurrency patterns; profiling, debugging, and performance tuning.

The book comprises 9 chapters, that will:

  • explain what Go is and present a short, complete program (chapters 1 and 2);
  • introduce the concept of packaging, discuss a project’s organization, and quickly present Go tools (chapter 3)
  • describe in some detail Go’s built-in data types and Go’s type system, including interfaces and type embedding, Go’s alternative approach to C++ virtual and non-virtual inheritance. Type embedding can be seen as a form of automated composition or delegation, in that an embedded type’s interface will be automatically exposed through the embedding type. Interfaces provide runtime polymorphism (chapter 4 and 5)
  • explore Go’s concurrency primitives: goroutines, which allows to execute a function in a light-weight process, and channels, which support type-safe, synchronized communication between coroutines. Beyond goroutines and channels, Go also supports memory sharing and traditional lock primitives. Additionally, a few advanced concurrency patterns are presented to implement channel-based watchdogs, to manage a pool of resources, and to handle a pool of workers (chapters 6 and 7)
  • introduce Go’s standard library, mostly focusing on three packages: log, json, and io (chapter 8)
  • show how you can use testing and benchmarking tools and how you can add example code to your documentation and use it for testing as well (chapter 9).

Go in Action contains more than 100 code samples, many of which are extracted from the standard library, so you may well say that this book provides real-world examples of how Go has been used to solve common problems.

InfoQ has spoken to Go in Action’s main author, William Kennedy, about his book.

Could you explain what was the motivation to write this book? Why was is it necessary?

I had already been writing my blog as a place for beginners to learn Go. I tried to not assume too much level of knowledge beyond the basics of programming. When I was asked the join the book, I took it as an opportunity to continue what I was doing at a larger scale. At the time, there were only a couple of books that existed and they were starting to be outdated. I had read those books as well when I started to learn Go and felt my style of writing could produce a new perspective on the material.

Over 2 years later and I think the material is well covered in several different formats and books. I believe Donovan and Kernighan’s The Go Programming Language and Go in Action are the best books today to learn the mechanics, implementation and specification of the language.

Your book targets intermediate-level developers with some experience in programming. What advice would you give them when reading this book? What should they expect? What should they not expect?

The hardest but most important thing anyone can do when starting to learn Go is to look at Go with a fresh set of eyes. You must learn Go and write code in the way the language has been designed. The idioms are very important and nothing is an accident. If you write Go based on the idioms set forth by the language team and the community, anyone can have success. If you fight the idioms, you will get things to work, but you will be missing a lot of what is awesome about the language.

Go is often described as a pragmatic language. Could you summarise the kind of approach to programming that it fosters? What are the main defining characteristics of the language?

The core philosophy is simplicity. Write simple code that is easy to read. When things are simple, bugs are reduced, more people can participate and performance will follow. When you look at the language syntax it's not surprising it's minimalistic in nature. The language from the outside is not novel and does not try to be. From the inside it is cutting edge software that is breaking new ground to keep what is complex as simple as possible for the programmer. Productivity of the programmer is everything.

High-level support for concurrency is one of the most significant features in Go, which embraces the CSP paradigm and goroutines. Could you describe what benefits this model bring to the Go developer? How does it compare to alternative concurrency paradigms, such as actors?

Channels are a new tool for concurrent programming that is introduced by Go. Channels provide a way of orchestrating goroutines to perform workflows. There are also mechanical sympathies to goroutines and the way the Go runtime scheduler works. I believe the actor paradigm works very well with Go and channels.

Go does not make writing concurrent software any easier and I think too many people over engineer software with goroutines and channels. In the end they are tools that need to be learned and used properly. I know channels are what bring people to Go but what keeps people are how interfaces and composition work and the simplicity of the language.

Go has recently seen some adoption as a replacement for large Python script. Do you think this could be a stable trend? What are Go's features/characteristics that could help this happen?

I have been teaching at the corporate levels for close to two years. I am teaching people coding in Python, Ruby, Java and C in my classes. I think what is growing adoption is how productive programmers are using the language. Everyone can write code in Go and the performance gains are hard to walk away from. The combination of productivity and performance.

Go does away with the ideas of inheritance and type hierarchy, as they are commonly known in OOP. Yet, the way Go handle type composition and interfaces seems pretty effective. How would you describe this kind of programming paradigm? Have you ever sensed, in your experience with Go, that being able to derive a type from another would have been of help?

I think the biggest advantage of Go is the mechanics behind interfaces and embedding, plus how the compiler has been designed to make this simple for programmers to effectively use. Go is an object oriented programming language however this is not something you want to leverage all the time. Go does allow the programmer to take an existing type and reuse it and extend it. Go does allow programming with interfaces to be intuitive and type safe. This video might help you see this.

From a composition perspective, this blog post will show the details.

I wish I had time to put the composition example in the book. In the next revision I will.

Tooling is an important part of a language success. In your book, you focus on the language and its standard library. What is your opinion about the tools that are available for Go?

The tooling in Go is amazing. The language team has everything you need to help debug and analyze Go programs. The community is also building tooling to extend what the language team has already provided. Here are more topics you can explore from the training: testing, benchmarking, memory trace, schedule tracing, stack trace.

There is a sort of competition among new languages trying to emerge: Go, Rust, D, Scala, etc. What is Go's potential, in your opinion?

There is no competition. Each language is solving different problems and can live together, even in the same stack. I love Rust and its potential for what it provides. I think the language syntax makes it difficult for people to jump into it, it will take some time. Rust is a language I would like to learn.

Get a 38% discount by using the code "goiaiq" when buying the book on the publisher's website.

You can download a sample of the Go in Action to get an impression of the book.

About the Book Author

William Kennedy is a managing partner at Ardan Studios in Miami, FL, a mobile, web app and systems development company. He is also a co-author of the book Go In Action , the author of the blog GoingGo.Net and the organizer for the Go and MongoDB meetup in Miami. Bill is focused on Go education and through his new venture Ardan Labs, Bill can often be found talking at conferences and giving workshops both locally and over hangouts. He always finds time to work with individuals and groups who want to take their Go knowledge, blogging and coding skills to the next level. @goinggodotnet

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT