Share your repls and programming experiences

← Back to all posts
This is what happened when I followed the wiki tutorial for golang
vityavv (31)

I'm sorry for what is about to follow

test

test

test

  • asb
  • bsa
  • asb
test

or

func main() {
  //print hello world
  //This is a really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really long comment
  fmt.Println("Hello, World!")
}

Sneek peak time

//The function doesn't take anything, but it returns a slice of pages. The reason you see (fpPages []Page) in the return is because it already defines fpPages in the begining of the function, and then I can just type "return", without anything, and it will return the fpPages variable. This is a really cool feature of go
func GetFrontPage() (fpPages []Page) {
	//make a new slice of pages, with the *capacity* to hold 5, but a length of zero. This is some weird memory managament wizzard magic I saw online, but lengths and capacities are covered extensibly in the tour of go (have you read that yet? ;)
	fpPages = make([]Page, 0, 5)
	//Woah! Where did this getPageNumbers come from? I'll explain, right after this
	pageNumbers := getPageNumbers()
	//this for loop counts down backwards from the last element in the page numbers to the fifth-to-last
	for i := len(pageNumbers) - 1; i > len(pageNumbers) - 6; i-- {
		//Sometimes there's less than 5 elements, so we have to make sure that the page actually exists
		if i >= 0 {
			//this uses the built-in append to add the new page to the fpPages slice
			fpPages = append(fpPages, pages[pageNumbers[i]])
		} else {
			//in case it doesn't exist, it just adds an empty page struct, which makes everything the nil value.
			fpPages = append(fpPages, Page{})
		}
	}
	//as discussed earlier, I just have to type return, since the computer already knows that I'm returning fpPages
	return
}

okay, I'm done, enjoy my repl