Go Concepts - The Type System: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 15: Line 15:
=Zero Value=
=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.
''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 (reference types).


=Number=
=Number=

Revision as of 22:00, 16 March 2016

Internal

Overview

Go is statically typed. Go designers tried to alleviate some of the "heaviness" associated with statically typed languages and made it "feel" 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.

Value and Reference Types

Zero Value

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

Number

String

String Operators and Functions

Built-in Types

Arrays

Slices

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

Maps

Conversion Between Types