Go Concepts - The Type System: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Go Concepts")
 
Line 2: Line 2:


* [[Go Concepts#Subjects|Go Concepts]]
* [[Go Concepts#Subjects|Go Concepts]]
=Types=
Go is ''statically typed''. Dynamically typed languages are convenient, but certain types of errors cannot be caught until the program executes. For statically typed languages, many of these errors are caught at the compilation phase. On the downside, static languages usually comes with a great deal of ceremony around everything that happens in the program (heavy syntax, type annotations, complex type hierarchies). Go gets rid of some of these and "feels" like a dynamic language. For example Go uses ''local type inference'', which eliminates the need to specify the type unnecessarily in program, the compiler figures it out.
Go is ''strongly typed'' meaning that yes cannot be unsafely coerced into other types they're not, or at least without programmer giving explicit permission. In JavaScript, for example, implicit conversion is done based on complicated rules that are not always easy to remember.
For more details on typing, see [[Programming#Static_Typing_vs_Dynamic_Typing|static typing vs. dynamic typing]] and [[Programming#Strong_Typing_vs_Loose_Typing|strong typing vs. loose typing]].
==Zero Value==
''Zero value'' for a specific type: 0 for <tt>int</tt>s, 0.0 for <tt>float</tt>s, "" for <tt>string</tt> and <tt>nil</tt> for pointers.
==Number==
==String==
===String Operators and Functions===
==Built-in Types==
===Arrays===
===Slices===
Slice built-in functions <tt>[[go Built-In Function append|append()]]</tt>, <tt>[[go Built-In Function copy|copy()]]</tt>.
===Maps===
==Conversion Between Types==

Revision as of 19:40, 16 March 2016

Internal


Types

Go is statically typed. Dynamically typed languages are convenient, but certain types of errors cannot be caught until the program executes. For statically typed languages, many of these errors are caught at the compilation phase. On the downside, static languages usually comes with a great deal of ceremony around everything that happens in the program (heavy syntax, type annotations, complex type hierarchies). Go gets rid of some of these and "feels" like a dynamic language. For example Go uses local type inference, which eliminates the need to specify the type unnecessarily in program, the compiler figures it out.

Go is strongly typed meaning that yes cannot be unsafely coerced into other types they're not, or at least without programmer giving explicit permission. In JavaScript, for example, implicit conversion is done based on complicated rules that are not always easy to remember.

For more details on typing, see static typing vs. dynamic typing and strong typing vs. loose typing.

Zero Value

Zero value for a specific type: 0 for ints, 0.0 for floats, "" for string and nil for pointers.

Number

String

String Operators and Functions

Built-in Types

Arrays

Slices

Slice built-in functions append(), copy().

Maps

Conversion Between Types