Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon

Go introduces generic codes and a new contract draft design at GopherCon 2019

Save for later
  • 3 min read
  • 29 Jul 2019

article-image
Update: On 31st July, Ian Lance Taylor posted in detail explaining the benefits and costs of including generics in Go. He also briefly discussed the draft design to convey how generics is going to be added to the Go language. Taylor says “Our goal is to arrive at a design that makes it possible to write the kinds of generic code, without making the language too complex to use or making it not feel like Go anymore.”

Check out the Goland blog for more details.

On 26th July at GopherCon 2019, Ian Lance Taylor introduced generics codes in Go. He briefly explained the need, implementation and benefits from generics for the Go language. Next, Taylor reviewed the Go contract design draft which included addition of optional type parameters to types and functions.

https://twitter.com/ymotongpoo/status/1154957680651276288

https://twitter.com/lelenanam/status/1154819005925867520

Taylor also proposed guidelines for implementing generic design in Go.

https://twitter.com/chimeracoder/status/1154794627548897280

In all the three years of Go surveys, lack of generics has been listed as one of the three highest priorities for fixing the Go language.

Taylor defines generic as “Generic programming which enables the representation of functions and data structures in a generic form, with types factored out.”

Generic code is written using types, which are specified later. An unspecified type is called as type parameter. A type parameter offers support only when permitted by contracts.

A generic code imparts strong basis for sharing codes and building programs. It can be compiled using an interface-based approach which optimizes time as the package is compiled only once. If a generic code is compiled multiple times, it can carry compile time cost.

Some of the many functions that can be written generically in Go include -

go-introduces-generic-codes-and-a-new-contract-draft-design-at-gophercon-2019-img-0

Image Source: Source graph


Go already supports two generic data structures which are built using Slice and Map languages. Go requires data structures to be written only once and then reused after putting it in a package.

The contract draft design states that since Go is designed to support programming, a clear contract should be maintained between a generic code and a calling code. With the new changes, users may find the language more complex. However, the Go team expects users to not write generic code themselves, instead use packages that are written by others using generic code.

Developers are very happy that the Go generics proposal is simple to understand and enables users to depend on the already written generic packages. This will save them time as users need not rewrite type specific functions in Go.

https://twitter.com/lizrice/status/1154802013982449666

https://twitter.com/protolambda/status/1155286562659282952

https://twitter.com/arschles/status/1154793543149375488

https://twitter.com/YvanDaSilva/status/1155432594818969600

https://twitter.com/mickael/status/1154799370610466816

Users have also admired the new contract design draft by the Go team.

https://twitter.com/miyagawa/status/1154810546002153473

https://twitter.com/t_colgate/status/1155380984671551488

https://twitter.com/francesc/status/1154796941227646976

Head over to the Google proposal page for more details on the new contract draft design.

Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at €18.99/month. Cancel anytime

Read More


Ian Lance Taylor, Golang team member, adds another perspective to Go being Google’s language

Is Golang truly community driven and does it really matter?

Go User Survey 2018 results: Golang goes from strength to strength, as more engineers than ever are using it at work