Go (programming language): Difference between revisions

Content deleted Content added
Linuxjava (talk | contribs)
No edit summary
Syntax: not sure this is useful, but give examples of returning both or neither of value+error, and change phrasing from "empty" since an "empty" int is 0
Line 54:
 
===Syntax===
Go's syntax includes changes from C aimed at keeping code concise and readable. The programmer needn't specify the types of expressions, allowing just <code>i := 3</code> or <code>s := "some words"</code> to replace C's <code>int i = 3;</code> or <code>char* s = "some words";</code>. Semicolons at the end of lines aren't required. Functions may return multiple, named values, and returning a <code>result, err</code> pair is the conventional way a function indicates an error to its caller in Go.{{efn|1=Usually, exactly one of the result and error values ishas non-empty,a butvalue other than the type's zero value; sometimes neitherboth do, as when a read or bothwrite maycan only be valid.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 maps and 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, and maps.
 
===Types===