Slide 1

Slide 1 text

Day #5 - Arrays A simple overview of arrays in Go 「 Trying to make you to fall in love with Golang 」 1 / 8 Arrays Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/

Slide 2

Slide 2 text

What is an Array An array is a collection of the same data type. has a fixed length - the size of an array cannot vary The literal representation of an array type is [n]T , where n is the size and T is the element type. Try it! 「Trying to make you to fall in love with Golang」 - Arrays 2 / 8 Arrays Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/

Slide 3

Slide 3 text

Letting the compiler deducing the length We can use the ... operator in place of size n in [n]T array type syntax. Go will deduce the size of the array Try It! 「Trying to make you to fall in love with Golang」 - Arrays 3 / 8 Arrays Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/

Slide 4

Slide 4 text

Nested Composite Literals Can Be Simplified If a composite literal nested many other composite literals, then those nested composited literals can simplified to the form {...} Try It! 「Trying to make you to fall in love with Golang」 - Arrays 4 / 8 Arrays Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/

Slide 5

Slide 5 text

Array comparison ( == ) Two arrays are equal if ... they are of the same type contains the same values all the values are in the same order Try It! 「Trying to make you to fall in love with Golang」 - Arrays 5 / 8 Arrays Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/

Slide 6

Slide 6 text

Array iteration To iterate over an array we can use a classic C-style for loop the range operator which returns index and value for each element in the array Try It! 「Trying to make you to fall in love with Golang」 - Arrays 6 / 8 Arrays Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/

Slide 7

Slide 7 text

Arrays in Go are value types When you assign an array to a new variable or pass an array to a function, the entire array is copied. any changes to this copied array, won't affect the original array Try It! 「Trying to make you to fall in love with Golang」 - Arrays 7 / 8 Arrays Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/

Slide 8

Slide 8 text

Thank you Luca Sepe Solution Architect (@day) / Software Craftsman (@night) {twitter.com, github.com, linkedin.com} / lucasepe 「Trying to make you to fall in love with Golang」 - Arrays 8 / 8 Arrays Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/