Go in Action from Manning and go installed

I’ve been hearing about the Go programming language here and there and when I’ve seen the freely available chapter from the upcoming book Go in Action from Manning I thought I’d give it a go. It’s an introductory material to Go and the why’s one could pick the language for the next project. What I liked about the chapter — yes, you’re reading it right, about the chapter not the language — were the questions to answer before picking a language, which in this case is Go. If a language wants to stand out it either has to offer a perfect implementation of an already-available-somewhere-but-not-so-elegantly-implemented feature or find its niche and hence face new challenges that lead to new criteria for a language. I have never considered quite a few before, and they do point out useful language features. It could only be for the additional features of how to select a language for a project that the chapter is worth your time.

The free chapter 1 “Introducting Go” is available at http://www.manning.com/ketelsen/ – a very useful and highly recommended reading! It seems so complete that I found no place to improve (except elaborating on Go’s features which I think is going to be a part of the other chapters). I thought it’s only about Go’s features without showing an example program, but section 1.3 “Hello, Go” does that — it offers the feel of Go by seeing a sample in action. It’s the hello.go from the website http://golang.org/, though.

Main points of the chapter and hence Go — some are exact copies of the sentences from the book:

  • Computers evolved yet programming languages not much
  • even your mobile phone is now smartphone with more cores than computers few years back
  • software developed by multiple teams spread around the globe
  • sharing code in Go is a built-in feature (whatever it means — I dunno)
  • use all cores with ease in Go
  • compilation in Go is lightning fast — you might not notice it at all
  • every programming language comes with a bunch of tradeoffs
  • static vs dynamic languages — a choice to make when picking a programming language
  • dynamic language suited for scripting
  • can’t verify the data in code is what’s on input
  • more code in dynamic language needs more tests (to verify correctness)
  • static languages give type safety yet can frustrate with repetition
  • productivity killer = code, compile, test…lather, rinse, repeat
  • deploying compiled code is a breeze
  • we can do better with the benefits of dynamic and interpreted languages with the speed and safety of static and compiled languages
  • passing thought to concurrency?
  • Ruby and Python use Global Interpreter Lock to ensure thread-safety and mitigate race-conditions => reducing performance due to one thread of execution
  • Java has concurrency primitives and often require tons of boilerplate for concurrent applications
  • We need a language with concurrency as a first-class citizen
  • a compelling feature of a language = how much done without using external libraries
  • hard to do much beyond simple text manipulation
  • Go a language with all the heavy lifting done?
  • developers make uncomfortable choice between rapid development and performance
  • fast execution vs rapid development? Can we have both? Go?
  • Go is a high performance language with development fast
  • Go has a concise syntax with very few keywords — not much to remember
  • Built-in concurrency features of Go — software scales to use resources available — one of the strongest feature of Go
  • Go uses a simple and effective type system
  • Go has a modern garbage collector — no need to manage memory yourself
  • Go uses a mart compiler and simplified dependency resolution algorithms
  • Go compiler look at the libraries you directly include
  • Many Go apps compile under a second
  • Entire Go source tree compiles under twenty secs
  • Goroutines are like threads but use less memory and less code to implement
  • Channels are typed memory queues to send messages between gorountines
  • Go facilities a model with data being sent to goroutines
  • Goroutines are functions that run concurrently
  • Many goroutines execute on a single thread
  • Writing a web server with web requests handled simultaneously? Use Go’s goroutines and net/http library
  • inbound requests processed on goroutine
  • Go runtime schedules execution of goroutines from a configurable pool of threads
  • Less development effort to achieve more
  • Goroutines run on one or more system threads
  • Keyword go to launch a function as a goroutine
  • It’s not uncommon to spawn tens of thousands of goroutines
  • Channels as a pipeline to enable safe data exchange between goroutines
  • channels as a shared memory access
  • channels enforce a single goroutine modify shared data
  • goroutine has exclusive control of data it receives on channel
  • Flexible hierarchy-free type system in Go
  • Simplicity of Go’s type system
  • Go developers embed types for re-use in Composition design pattern
  • Your types in Go are composed of smaller types
  • You don’t need to declare you implement interface in Go — let the compiler figure that out from the code
  • Many interfaces in Go’s standard library are very small with only a few functions
  • Go has built-in types like int or string and user-defined ones.
  • Go’s user-defined types look and operate similarly to C’s struct
  • Types may declare methods
  • inheritance vs composition
  • Go interfaces model small behaviours
  • Interfaces express capabilities of type
  • Duck typing when a type offers specific set of capabilities without specifying interface implemented
  • if it quacks like a duck, then it can be a duck
  • In Go, when type has methods of interface without specifying it explicitly, it can be used anywhere the interface’s expected
  • Go’s interface typically represents a single action
  • Most common interface – io.Reader
  • Go’s interfaces are smaller and single-action mostly
  • Go makes interfaces fun, elegant, and flexible
  • Go programs are packages
  • import enables external code
  • fmt package to format and print data
  • main() function is an entry point of application
  • You can use Go right from the browser – Go Playground at http://play.golang.org
  • Go developers use Go Playground to share code ideas, test theories or debug their code
  • Go Playground to solicit help
  • Project Kiev

After having reading the book, I installed the Go binary distribution for Mac OS X from https://code.google.com/p/go/downloads/list. It takes few seconds to install.

$ cat hello.go
package main

import "fmt"

func main() {
  fmt.Printf("hello, world\n")

$ go run hello.go
hello, world
Be Sociable, Share!
This entry was posted in Languages.

One Response to Go in Action from Manning and go installed

  1. bketelsen says:

    Hi Jacek. Thank you for your thoughtful write-up of our first few chapters. We look forward to your feedback as we release more.

Leave a Reply

%d bloggers like this: