Go Concepts - The Type System: Difference between revisions
Line 54: | Line 54: | ||
=Primitive vs. Non-Primitive Nature= | =Primitive vs. Non-Primitive Nature= | ||
=Duck Typing= | |||
For more details on duck typing go [[Programming#Duck_Typing|here]]. |
Revision as of 23:56, 21 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, false for Booleans and nil for pointers. For reference types, their underlying data structures are initialized to their zero values.
Number
String
String Operators and Functions
User-Defined Types
struct
Are all users can define (in terms of types) structs, or there are other user-defined types?
interface
Can only structs be interfaces, or there are other things that can be interfaces?
Built-in Types
Arrays
Slice
A slice is a reference type that implements a dynamic array.
Slice built-in functions append(), copy().
TODO Deep difference between slice and array (memory model, etc.)
Maps
Reference Types
Conversion Between Types
Primitive vs. Non-Primitive Nature
Duck Typing
For more details on duck typing go here.