Content deleted Content added
No edit summary Tags: Reverted Mobile edit Mobile web edit |
Dalamajama (talk | contribs) m Undid revision 1267132585 by Dalamajama (talk) |
||
(20 intermediate revisions by 18 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
Line 8:
| logo size = 128px
| logo caption =
| paradigm = [[Multi-paradigm programming language|Multi-paradigm]]: [[concurrent programming|concurrent]] [[imperative programming|imperative]], [[functional programming|functional]]<ref>{{Cite web |url=https://go.dev/doc/codewalk/functions/ |title=Codewalk: First-Class Functions in Go |quote=Go supports first class functions, higher-order functions, user-defined function types, function literals, closures, and multiple return values. This rich feature set supports a functional programming style in a strongly typed language.}}</ref> [[object-oriented programming|object-oriented]]<ref>{{Cite web |url=https://golang.org/doc/faq#Is_Go_an_object-oriented_language |title=Is Go an object-oriented language? |access-date=April 13, 2019 |quote=Although Go has types and methods and allows an object-oriented style of programming, there is no type hierarchy.}}</ref><ref>{{Cite web |url=https://talks.golang.org/2012/chat.slide#5 |title=Go: code that grows with grace |access-date=June 24, 2018 |quote=Go is Object Oriented, but not in the usual way.}}</ref>
| year = {{start date and age|2009|11|10}}
| designer = [[Robert Griesemer]]<br />[[Rob Pike]]<br />[[Ken Thompson]]<ref name="langfaq" />
Line 27:
| file_ext = .go
}}
'''Go''' is a fast<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> [[static typing|statically typed]], [[compiled language|compiled]] [[high-level programming language|high-level]] [[general purpose programming language]]. It is known for its simplicity and efficiency.<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> Its simplicity express through its basic syntax of the language itself and its large library that help the developer to have a small stack for its project. 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/ |access-date=January 18, 2010}}</ref> in 2009 by [[Robert Griesemer]], [[Rob Pike]], and [[Ken Thompson]].<ref name="langfaq">{{Cite web |date=January 16, 2010 |title=Language Design FAQ |url=http://golang.org/doc/go_faq.html |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 web |url=https://www.theregister.co.uk/2011/05/05/google_go/ |title=Google Go boldly goes where no code has gone before |last=Metz |first=Cade |date=May 5, 2011 |website=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:
*
*
A third-party [[source-to-source compiler]], GopherJS,<ref>{{Cite web | url=https://github.com/gopherjs/gopherjs | title=A compiler from Go to JavaScript for running Go code in a browser: Gopherjs/Gopherjs| website=[[GitHub]] |url-status=live |archive-url=https://web.archive.org/web/20231212143621/https://github.com/gopherjs/gopherjs |archive-date= Dec 12, 2023 }}</ref>
{{toclimit}}
==History==
Line 68 ⟶ 66:
===Versioning===
Go 1 guarantees compatibility<ref>{{Cite web|url=https://golang.org/doc/go1compat|title=Go 1 and the Future of Go Programs |website=The Go Programming Language}}</ref> for the language specification and major parts of the standard library. All versions up through the current Go 1.
Go does not follow [[SemVer]]; rather, each major Go release is supported until there are two newer major releases. Unlike most software, Go calls the second number in a version the major, i.e., in <code>1.x</code> <code>x</code> is the major version. <ref>{{Cite web|url=https://golang.org/doc/devel/release.html#policy|title=Release History|website=The Go Programming Language}}</ref> This is because Go plans to never reach 2.0, given that compatibility is one of language's major selling points.<ref>{{Cite web|url=https://go.dev/blog/compat|title=Backward Compatibility, Go 1.21, and Go 2|website=The Go Programming Language}}</ref>
Line 90 ⟶ 88:
Methods may return multiple values, and returning a <syntaxhighlight lang="Go" inline="">result, err</syntaxhighlight> pair is the conventional way a method indicates an error to its caller in Go.{{efn|Usually, exactly one of the result and error values has a value other than the type's zero value; sometimes both do, as when a read or write can only be partially completed, and sometimes neither, as when a read returns 0 bytes. See [[Semipredicate problem#Multivalued return|Semipredicate problem: Multivalued return]].}} Go adds literal syntaxes for initializing struct parameters by name and for initializing [[Associative array|maps]] and [[Array slicing|slices]]. As an alternative to C's three-statement <code>for</code> loop, Go's <code>range</code> expressions allow concise iteration over arrays, slices, strings, maps, and channels.<ref>{{Cite web|url=https://golang.org/ref/spec#For_statements|title=The Go Programming Language Specification |website=The Go Programming Language}}</ref>
<code>fmt.Println("Hello World!")</code> is a statement.
In Go, statements are separated by ending a line (hitting the Enter key) or by a semicolon "<code>;</code>".
Hitting the Enter key adds "<code>;</code>" to the end of the line implicitly (does not show up in the source code).
The left curly bracket <code>{</code> cannot come at the start of a line.<ref>{{Cite web |title=Go Syntax |url=https://www.w3schools.com/go/go_syntax.php |access-date=2024-11-23 |website=www.w3schools.com |language=en-US}}</ref>
===Types===
Line 128 ⟶ 134:
The first is ''embedding'', which can be viewed as an automated form of [[object composition|composition]].{{r|gohotdraw}}
The second are its ''[[protocol (object-oriented programming)|interface]]s'', which provides [[runtime polymorphism]].<ref name="balbaert">{{Cite book |last=Balbaert |first=Ivo |title=The Way to Go: A Thorough Introduction to the Go Programming Language |publisher=iUniverse |year=2012}}</ref>{{rp|266}} Interfaces are a class of types and provide a limited form of [[structural type system|structural typing]] in the otherwise nominal type system of Go. An object which is of an interface type is also of another type, much like [[C++]] objects being simultaneously of a base and derived class. The design of Go interfaces
The definition of an interface type lists required methods by name and type. Any object of type T for which functions exist matching all the required methods of interface type I is an object of type I as well. The definition of type T need not (and cannot) identify type I. For example, if {{mono|Shape}}, {{mono|Square}} {{mono|and Circle}} are defined as
Line 366 ⟶ 372:
===Web app===
The [https://pkg.go.dev/net/http net/http]<ref>{{Cite web |title=http package - net/http - Go Packages |url=https://pkg.go.dev/net/http |access-date=2024-11-23 |website=pkg.go.dev}}</ref> package provides support for creating web applications.
This example would show "Hello world!" when localhost:8080 is visited.
Line 495 ⟶ 501:
[[Category:Cross-platform free software]]
[[Category:Cross-platform software]]
[[Category:Free
[[Category:Google software]]
[[Category:High-level programming languages]]
|