Go (programming language): Difference between revisions

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)}}https://tdga.dga.or.th/index.php?lang=th
{{Use American English|date=August 2022}}https://www.oic.go.th/ginfo/index.asp
{{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>https://krungthai.com/th/personal
| 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:
 
* Google'sThe original, [[Self-hosting (compilers)|self-hosting]]<ref>{{Cite web |url=https://golang.org/doc/go1.5#implementation |title=Go 1.5 Release Notes |access-date=January 28, 2016 |quote=The compiler and runtime are now implemented in Go and assembler, without C.}}</ref> "gc" [[compiler]] [[toolchain]], targetinginitially multipledeveloped [[operatinginside system]]s and [[WebAssembly]].Google;<ref>{{Cite web |url=https://bloggithub.com/golang.org/go1.11go |title=The Go 1.11programming is Released |date=August 24, 2018language |access-date=January 1, 20192024-11-01}}</ref>
* gofrontend, aA frontend towritten other compilers, with the ''libgo'' library. Within [[GNU Compiler Collection|GCCC++]], thecalled combination is gccgo;gofrontend,<ref>{{Cite web |url=https://gccgithub.gnu.orgcom/installgolang/configure.htmlgofrontend |title=Installing GCC: Configurationgofrontend |access-date=December 3, 2011 |quote=Ada, Go and Objective2024-C++ are not default languages11-01}}</ref> withoriginally a [[LLVMGNU Compiler Collection|GCC]] thefrontend, combinationproviding isgccgo, gollvm.a GCC-based Go compiler;<ref>{{Cite web |url=httphttps://golanggcc.gnu.org/doconlinedocs/go_faqgcc-14.html#Implementation2.0/gccgo/ |title=FAQ: Implementationgccgo |access-date=August2024-11-01 2|quote=gccgo, 2021the |website=TheGNU Gocompiler Programmingfor Languagethe |access-date=AugustGo 2,programming 2021language}}</ref>{{efn|Using alternativelater backendsextended reducesto compilationalso speedsupport and[[LLVM]], Go'sproviding controlan overLLVM-based garbageGo collectioncompiler butcalled provides better machine-code optimizationgollvm.<ref>{{citeCite web |title=gollvm § Is gollvm a replacement for the main Go compiler? (gc)|url=https://go.googlesource.com/gollvm/ |websitetitle=GitGollvm at|access-date=2024-11-01 Google|quote=Gollvm is an LLVM-based Go compiler.}}</ref>}}https://www.settrade.com/th/links
 
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> compilestranspiles Go to [[JavaScript]] for [[front-end web development]].https://www.dga.or.th/
{{toclimit}}
https://www.set.or.th/th/home
https://thaiwhere.org/%E0%B8%98%E0%B8%99%E0%B8%B2%E0%B8%84%E0%B8%B2%E0%B8%A3/bank-place-19724fb0e730306516f47cd764ab74c2.html#gsc.tab=0
 
==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.2223 release<ref>{{Cite web|title=Go 1.2223 Release Notes|url=https://go.dev/doc/go1.2223|website=The Go Programming Language}}</ref> have maintained this promise.
 
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 werewas designedinspired afterby [[protocol (object-oriented programming)|protocol]]s from the Smalltalk programming language.<ref>{{Cite web |url=https://talks.golang.org/2015/gophercon-goevolution.slide#19 |title=The Evolution of Go |website=talks.golang.org |access-date=March 13, 2016}}</ref> Multiple sources use the term [[duck typing]] when describing Go interfaces.<ref>{{Cite web|last=Diggins|first=Christopher|date=November 24, 2009|title=Duck Typing and the Go Programming Language|url=http://www.drdobbs.com/architecture-and-design/duck-typing-and-the-go-programming-langu/228701527|access-date=March 10, 2016|website=Dr. Dobb's, The world of software development}}</ref><ref>{{Cite web |url=https://medium.com/@matryer/golang-advent-calendar-day-one-duck-typing-a513aaed544d#.ebm7j81xu |title=Duck typing in Go |last=Ryer |first=Mat |date=December 1, 2015 |access-date=March 10, 2016}}</ref> Although the term duck typing is not precisely defined and therefore not wrong, it usually implies that type conformance is not statically checked. Because conformance to a Go interface is checked statically by the Go compiler (except when performing a type assertion), the Go authors prefer the term ''structural typing''.<ref>{{Cite web |url=https://golang.org/doc/faq |title=Frequently Asked Questions (FAQ) - The Go Programming Language |website=The Go Programming Language}}</ref>
 
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 compilers and interpretersopen source compilers]]
[[Category:Google software]]
[[Category:High-level programming languages]]