The first installment in our five-week tutorial on Google's new native language explains how to set up Go and build programs. It then walks through code examples that highlight some of the language's interesting features.
In this installment, Go expert Mark Summerfield explains how to set up Go, and then he provides two examples of Go programs that are explained in depth. The programs provide a partial overview of Go's key features and some of its key packages. The following weeks' installments will show the remaining key features and dig into many aspects that make Go a uniquely interesting language, especially for C, C++, and Java programmers.
As explained in the editorial Why Not Go?, Go has many unique features and might be described as C for the 21st century. Given that one of the language's designers is Ken Thompson, the languages do indeed share a common ancestor. [read on]
In this second installment of our five-week course on the Go language, we explore Go's unusual approach to object orientation, its special built-in object types, the syntax for multiple return values, and how Go handles exceptions.
Although Go supports object-oriented programming, it provides neither classes nor inheritance (is-a relationships). Go does support the creation of custom types, and Go makes aggregation (has-a relationships) extremely easy. Go also allows for the complete separation of a type's data from its behavior, and supports duck typing. Duck typing is a powerful abstraction mechanism that allows values to be handled (for example, passed to functions) based on the methods they provide, regardless of their actual types. The terminology is derived from the phrase, "If it walks like a duck, and quacks like a duck, it's a duck." This produces a flexible and powerful alternative to the traditional classes and inheritance approach but it requires those of us used to the more traditional approach to make some significant conceptual adjustments to really benefit from Go's object orientation. [read on]
Go's unique approach to OO steps around many problems found in other languages by preferring composition to inheritance.
TTo an object-oriented purist, neither C++ nor Java are object-oriented because those languages use method calls rather than message passing. Pragmatists equally might question whether Go is object-oriented, since in addition to using methods rather than messages, it doesn't support inheritance. This apparent lack is a deliberate design choice which reflects a growing discontent with deep, complex object hierarchies that can be very inflexible to use and expensive to change. Many programmers are switching to using aggregation wherever possible, and Go provides particular support for this approach. [read on]
In this installment of our Go tutorial, Go's support for REST-based Web services and cloud computing make quick work of useful document analysis project.
Here, I have developed a Web service in Go that does useful data retrieval and exposes the results via a RESTful API, and I've rolled it out on the Google App Engine cloud. If your volumes (traffic and data) are less than a certain limit, you can use GAE for free. [read on]
In this final installment of our five-week tutorial series on Go, we examine the language's extensive standard library.
The Go standard library includes a large number of packages that provide a wide range of functionality. The overview provided here is highly selective and very brief. The contents of the library are likely to continue to grow after this article is published, so it is best to look at the library APIs online or locally using godoc (in the Go distribution) to get the most up-to-date information and get a comprehensive overview of what is available in each package.
exp (experimental) package is where packages that might potentially be added to the standard library begin life, so these packages should not be used unless you want to participate in their development (by testing, commenting, or submitting patches). The exp package is normally available when pulling Go from Google's Go source tree, but it may not be included in prebuilt packages. The other packages are OK to use, although at the time of this writing, some are still incomplete. [read on]