According to Larry Wall, the original author of the Perl programming language, there are three great virtues of a programmer; Laziness, Impatience and Hubris

  • Laziness: The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful and document what you wrote so you don't have to answer so many questions about it.
  • Impatience: The anger you feel when the computer is being lazy. This makes you write programs that don't just react to your needs, but actually anticipate them. Or at least pretend to.
  • Hubris: The quality that makes you write (and maintain) programs that other people won't want to say bad things about.

"A language that doesn't affect the way you think about programming is not worth knowing."

Alan J. Perlis (1922-1990), first recipient of the Turing Award

Parameters in Go are always passed by value, and a copy of the value being passed is made. If you pass a pointer, then the pointer value will be copied and passed. When a slice is passed, the slice value (which is a small descriptor) will be copied and passed - which will point to the same backing array (which will not be copied).


Go - Slice

Go'da slicelar bir fonksiyona parametre olarak verildiklerinde, orjinal value'yu referans ediyor. Bu sebeple fonksiyon icerisinde slice'in bir elemanini degistirdigimizde orjinal slice da degisir.

package main

import "fmt"

func main() {
    a := []int{1, 2, 3, 4}

    fmt.Println(a) // [10, 2, 3, 4]

func foo(s []int) {
    s[0] = 10


Yukarida goruldugu gibi foo fonksiyonuna slice'i pointer olarak vermememe ragmen orjinal slice degisti.

Go Slices: usage and internals


func m() (i int){
    defer func(){i++}
    return 1

m() // 2