Go (programming language): Difference between revisions

Content deleted Content added
https://support.apple.com/HT212878?cid=iOS_SettingsUI_iphone_article_HT212878
added archive-url, added metadata, replaced outdated urls
 
(8 intermediate revisions by 8 users not shown)
Line 1:
{{short description|Programming language}}
{{for|the 2003 agent-based programming language|Go! (programming language)}}
{{Use American English|date=August 2022}}
{{Use mdy dates|date=October 2018}}
{{Infobox programming language
| name = Go
| name = [https://support.apple.com/HT212878?cid=iOS_SettingsUI_iphone_article_HT212878 Go]
| logo = Go Logo Blue.svg
| logo size = 230px
Line 15:
| latest_test_version =
| latest_test_date = <!--{{start date and age|2016|08|08}}<ref name="preview_page">{{Cite web |url=https://golang.org/dl/ |title=Release History |website=The Go Programming Language |access-date=August 8, 2016}}</ref>-->
| typing = [[type inference|Inferred]], [[static typing|static]], [[strong typing|strong]],<ref name="go-introduction">{{citeCite web |title=The Go Programming Language Specification |url=https://go.dev/ref/spec#Introduction |url-status=live title|archive-url=Thehttps://web.archive.org/web/20250813094237/https://go.dev/ref/spec#Introduction Go|archive-date=August Programming13, Language2025 Specification - the|work=The Go Programming Language }}</ref> [[structural typing|structural]],<ref name="structural_typing">{{Cite web |url=https://golang.org/doc/faq#implements_interface |title=Why doesn't Go have "implements" declarations? |websiteurl=Thehttps://go.dev/doc/faq#implements_interface Go|url-status=live Programming|archive-url=https://web.archive.org/web/20250728222723/https://go.dev/doc/faq#implements_interface Language|archive-date=July 28, 2025 |access-date=October 1, 2015 |website=The Go Programming Language }}</ref><ref name="pike-20141222">{{Cite webtweet |url=https://twitter.com/rob_pike/status/546973312543227904 |titlefirst=Rob Pike on Twitter |last=Pike |firstnumber=Rob546973312543227904 |dateuser=December 22, 2014rob_pike |access-date=March 13, 2016 |quotetitle=Go has structural typing, not duck typing. Full interface satisfaction is checked and required. |urlauthor-statuslink=deadRob Pike |date=December 22, 2014 |access-date=March 13, 2016 |archive-url=https://web.archive.org/web/20220407025913/https://twitter.com/rob_pike/status/546973312543227904 |archive-date=April 7, 2022 |url-04-07status=dead }}</ref> [[nominal typing|nominal]]
| memory management = [[Garbage collection (computer science)|Garbage collection]]
| implementations = gc, gofrontend, [[Elements_Toolchain|gold]]
| programming language = Go, [[Assembly language]] (gc); [[C++]] (gofrontend)
| website = {{url|[https://support.apple.com/HT212878?cid=iOS_SettingsUI_iphone_article_HT212878 https://go.dev/]}}
| influenced_by = {{#statements:influenced by}}
| influenced = [[Crystal (programming language)|Crystal]], [[V (programming language)|V]]
| operating_system = [[DragonFly BSD]], [[FreeBSD]], [[Linux]], [[macOS]], [[NetBSD]], [[OpenBSD]],<ref name="openbsd">{{Cite web |url=http://ports.su/lang/go |title=lang/go: go-1.4 |date=December 23, 2014 |website=OpenBSD ports |access-date=January 19, 2015}}</ref> [[Plan 9 from Bell Labs|Plan 9]],<ref>{{Cite web |url=http://go-lang.cat-v.org/os-ports |title=Go Porting Efforts |date=January 12, 2010 |website=Go Language Resources |publisher=cat-v |access-date=January 18, 2010}}</ref> [[Solaris (operating system)|Solaris]], [[Windows]]
| license = [[3-clause BSD]]<ref name="license">{{Cite web |title=Text file LICENSE |url=httphttps://golanggo.orgdev/LICENSE |titleurl-status=Text filelive |archive-url=https://web.archive.org/web/20250716050530/https://go.dev/LICENSE |websitearchive-date=TheJuly Go16, Programming Language2025 |access-date=October 5, 2012 |website=The Go Programming Language }}</ref> + [[software patents|patent]] grant<ref name="gopatens">{{Cite web |title=Additional IP Rights Grant |url=httphttps://golanggo.orgdev/PATENTS |titleurl-status=Additionallive IP Rights Grant|archive-url=https://web.archive.org/web/20250330185005/https://go.dev/PATENTS |websitearchive-date=TheMarch Go30, Programming Language2025 |access-date=October 5, 2012 |website=The Go Programming Language }}</ref>
| file_ext = .go
}}
 
'''Go''' is a [[high-level programming language|high-level]] [[general purpose programming language]] that is [[static typing|statically typed]] and [[compiled language|compiled]]. It is known for the simplicity of its syntax and the efficiency of development that it enables by the inclusion of a large standard library supplying many needs for common projects.<ref>{{Cite web |title=Go Introduction |url=https://www.w3schools.com/go/go_introduction.php |access-date=2024-11-23 |website=www.w3schools.com |language=en-US}}</ref> It was designed at [[Google]]<ref name="techcrunch">{{Cite news |last=Kincaid |first=Jason |date=November 10, 2009 |title=Google's Go: A New Programming Language That's Python Meets C++ |language=en-US |work=TechCrunch |url=https://techcrunch.com/2009/11/10/google-go-language/ |archive-url= |archive-date= |access-date=January 18, 2010 |work=[[TechCrunch]] }}</ref> in 2007 by [[Robert Griesemer]], [[Rob Pike]], and [[Ken Thompson]], and publicly announced in November of 2009.<ref name="langfaq">{{Cite web |date=January 16, 2010 |title=Language Design FAQ |url=httphttps://golanggo.orgdev/doc/go_faqfaq |url-status=live |archive-url=https://web.htmlarchive.org/web/20250728222723/https://go.dev/doc/faq |archive-date=July 28, 2025 |access-date=February 27, 2010 |website=The Go Programming Language |language=en-US}}</ref> It is [[syntax (programming languages)|syntactically]] similar to [[C (programming language)|C]], but also has [[memory safety]], [[garbage collection (computer science)|garbage collection]], [[structural type system|structural typing]],<ref name="structural_typing" /> and [[communicating sequential processes|CSP]]-style [[concurrency (computer science)|concurrency]].<ref name="boldly">{{Cite webnews |urllast=https://www.theregister.co.uk/Metz |first=Cade |date=May 5, 2011/05/05/google_go/ |title=Google Go boldly goes where no code has gone before |lasturl=Metzhttps://www.theregister.com/2011/05/05/google_go/ |firsturl-status=Cadelive |archive-url=https://web.archive.org/web/20250728222723/https://go.dev/doc/faq |archive-date=MayJuly 528, 20112025 |websitework=[[The Register]] }}</ref> It is often referred to as '''Golang''' to avoid ambiguity and because of its former ___domain name, <code>golang.org</code>, but its proper name is Go.<ref>{{Cite web |url=https://go.dev/doc/faq#go_or_golang |title=Is the language called Go or Golang? |access-date=March 16, 2022 |quote=The language is called Go.}}</ref>
 
There are two major implementations:
Line 87:
** A toolchain that, by default, produces [[static library|statically linked]] native binaries without external Go dependencies
* A desire to keep the language specification simple enough to hold in a programmer's head,<ref>{{cite web|last=Pike|first=Rob|url=http://5by5.tv/changelog/100|title=The Changelog|type=Podcast|access-date=October 7, 2013|archive-date=October 20, 2013|archive-url=https://web.archive.org/web/20131020101046/http://5by5.tv/changelog/100|url-status=dead}}</ref> in part by [[#Omissions|omitting features that are common in similar languages]].
* 25 reserved words
 
===Syntax===
Line 222 ⟶ 223:
==={{anchor|Concurrency}} Concurrency: goroutines and channels===
[[File:DotGo 2015 - Matt Aimonetti - Applied concurrency in Go.webm|thumb|DotGo 2015 - Matt Aimonetti - Applied concurrency in Go]]
The Go language has built-in facilities, as well as library support, for writing [[concurrent programming|concurrent programs]]. The runtime is [[asynchronous I/O|asynchronous]]: program execution that performs, for example, a network read will be suspended until data is available to process, allowing other parts of the program to perform other work. This is built into the runtime and does not require any changes in program code. The go runtime also automatically schedules concurrent operations (goroutines) across multiple CPUs; this can achieve parallelism for a properly written program.<ref name="concurrency-is-not">{{cite web|last=Pike |first=Rob |url=http://vimeo.com/49718712 |title=Concurrency is not Parallelism|date=September 18, 2012 }}</ref>
 
The primary concurrency construct is the ''goroutine'', a type of [[green thread]].<ref name=":0">{{Cite book |last1=Donovan |first1=Alan A. A. |title=The Go programming language |last2=Kernighan |first2=Brian W. |date=2016 |publisher=Addison-Wesley |isbn=978-0-13-419044-0 |series=Addison-Wesley professional computing series |___location=New York, Munich |pages=}}</ref>{{Rp|pages=280-281}} A function call prefixed with the <code>go</code> keyword starts a function in a new goroutine. The language specification does not specify how goroutines should be implemented, but current implementations multiplex a Go process's goroutines onto a smaller set of [[thread (computer science)|operating-system threads]], similar to the scheduling performed in [[Erlang (programming language)|Erlang]] and [[Haskell (programming language)|Haskell's GHC runtime implementation]].{{r|phrasebook}}{{rp|10}}