[Go] Starting with Go

My goal here is to learn one programming language and one scripting language. The scripting language which I am currently practising is python, and once I have enough experience in doing python I will learn Ruby on Rails. The programming language I am learning now is Go, what attracts me is its built-in concurrency by simply calling the go to indicate I need to execute the function concurrently, this is very different from python which I need to import threading.

So here are things which I have found out so far.
The Go programming language compiles for the package main, you can create other packages as a module to be imported by other names, but only the package main is compiled.

Second, you declare a public function of a package by capitalizing the first character of the function name, if the first character of the function name is not capitalized then it is considered a private function which cannot be called after the package is imported.
The Useless package

package useless

import "fmt"

func CallUselessFunction() {
	fmt.Println("This is a useless function.")
}

So I created a useless module, as you can see the first letter of the function name CallUselessFunction() is capitalized, this indicates after I imported the package useless into my package main I can call the function.

package	main

import (
	"lab1/useless"
)

func main() {
	useless.CallUselessFunction()
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s