Categories
Programming

Go and Zed Documentation – Basics

This blog is totally mine now, and I don’t care who reads it or not. Anyway, this is my documentation for Go and Zed. I’ll update it here to keep information for myself. (Yes, I just began to practice Go.) The Zed editor is also a bit new for me, which is why I created this article.

Don’t expect official or so structured documentation btw it’s for myself.

package main

import "fmt"

func main() {
	fmt.Println("Hello World")
}

It looks like I don’t need a semicolon in this language, which is pretty cool. We are using packages to import functions, and we have a main function to start with. It seems that ‘fmt’ includes output and input functions.

Zed shortcuts that I used instantly :

  1. Command + J : toggle terminal

2. Command + Shift + M : Project diagnostics (basically error window)

3. Command + P : open files

package main

var y int = 10

func main() {
	x := 10
}

It’s kind of a weird way to assign local variables, but I can get used to it.

package main

import "fmt"

var y int = 10

func main() {
	x := 15

	if y > x {
		fmt.Println("y is bigger than x bla bla")
	} else if y == x {
		fmt.Println("same shit")
	} else {
		fmt.Println("x is bigger than y bla bla")
	}
}

The if-else statement looks like C++ and Python had a baby.

package main

func main() {
	const PI = 3.14
}
package main

import "fmt"

func main() {
	for i := 0; i < 10; i++ {
		fmt.Println(i)
	}
}

It seems closer to C++, well it makes everything easier.

i := 0
for i < 10 {
  fmt.Println(i)
  i++
}

It seems we don’t have a while loop, but we can use a for loop like a while loop. Cool, fine!

package main

import "fmt"

func main() {
	arr := []int{1, 2, 3}
	for i, v := range arr {
		fmt.Println(i, v)
	}
}

Let ‘i’ represent how many times the loop runs, and ‘v’ represent the elements in the array.

if x := 10; x > 0 {
  fmt.Println("Positive")
} else {
  fmt.Println("Non-positive")
}

I also found you can declare variable inside a condition.

Leave a Reply

Your email address will not be published. Required fields are marked *