6

Go 1.20: The Golang Programming Language Adds New Changes

 1 year ago
source link: https://devm.io/go/go-1-20-new-features
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Introducing four new language features

Go 1.20: The Golang Programming Language Adds New Changes

Sarah Schlothauer

03. Feb 2023


The latest update for Google’s statically typed programming language, Go 1.20, adds some improvements to the language, and some minor changes to its standard library and tools. Additionally, it adds preview support for profile-guided optimization, also known as PGO.

Go has promised to always maintain compatibility with Go version 1.0 According to its documentation in the section “Go 1 and the Future of Go Programs”:

It is intended that programs written to the Go 1 specification will continue to compile and run correctly, unchanged, over the lifetime of that specification. At some indefinite point, a Go 2 specification may arise, but until that time, Go programs that work today should continue to work even as future "point" releases of Go 1 arise (Go 1.1, Go 1.2, etc.).

Therefore, this release will not cause any breaking changes in Go 1 code in your projects. Let’s have a look at some of its notable changes introduced in Golang version 1.20.

Language changes

The release of Go 1.20 introduces four new changes to the language.

Allow conversions from a slice to an array

Piggybacking off of an improvement in Go 1.17 which added conversions from slice to an array pointer, Go 1.20 now allows conversions from a slice to an array.

Three new functions

Three functions can now be defined by the unsafe package: SliceData, String, and StringData. According to Go's documentation, unsafe "provides facilities for low-level programming including operations that violate the type system".

Struct value changes

Now, struct values can be compared one field at a time, in contrast to previous versions. With this language change, array values will now also be read in increasing order, one at a time.

Comparable types improvement

With Go 2.0, comparable types can now satisfy comparable constraints. This is possible even when the type arguments are not necessarily considered to be strictly comparable. (Types are strictly comparable if they are comparable, are not an interface type, or are not composed of an interface type.)

Library changes

The core Go library receives a few small updates. According to the release notes, here’s what’s been added:

  • New crypto/ecdh package
  • HTTP ResponseController
  • Support for error wrapping multiple errors
  • New ReverseProxy Rewrite hook function

Other notable changes and improvements

Some other changes added in Go 1.20 include:

  • The $GOROOT/pkg directory will no longer store pre-compiled package archives for the standard library. This new feature will help reduce the size of Go distribution models.
  • On systems that do not have a C toolchain, by default the go command will now disable cgo. Additionally, if Go is installed on a system that doesn't have a C compiler, the system will use pure Go builds in the standard library.
  • Improvements have been made to go test -json, so that now programs using it do not need to be updated.
  • More Go type binaries are now supported by the go version -m.
  • Anonymous interface cycles are now no longer allowed in the compiler.
  • Thanks to some improvements in the garbage collector’s internal data, users will now experience more CPU efficiency. The documentation reports up to a 2% increase.
  • Preview support for PGO (profile-guided optimization) has been added. This could potentially also help with performance improvements and optimizations. Users should keep it mind that this is only in a preview state for now and may change in future releases.

For a comprehensive list of every new change in Go 1.20, including minor library changes and a list of OS compatibility, refer to the release documentation.

Are you currently using the latest release? You can check which version of Go you are currently using with the command go version.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK