Sunday, November 15, 2009

Google Go language on Google Wave

If you have an account on Google Wave service, and you want to know about golang something more - you should join the Go language wave.
To do it just write in the search string

with:public tag:golang, issue9


But if you have no account in Wave, but you want it - just write a comment with your email, and i will send you invite (I have only 7, so you should hurry!)

There were some problems with posting a comment, so you can just follow me (@go_lang) on twitter, and write a DM with your email.

Go program structure

So now I want to talk about structure of Go programm.

Every program must start from the package name. Your first program was starting from the main package, and it was
package main

Name of the package can be different.

Than, if you need, you should import some packages, for exapmle "fmt" or "math". In "Hello world!" prog we import fmt package, because we need the Printf function, which is in these (fmt) package. Full list of packages and functions, which they have you can see on the home page of the Go language: link. It's not an mandatory part, but in more then 90% you need to export some standart packages.

Next is the program code. You can first define vars with
var name = 1
var name1 = 2*60

or something like that. Then goes functions part. The main function is "main", so if you write
func main() {
fmt.Printf("Hi! \n")
}

it will write "Hi!". Also you can write other functions:
package main


import "fmt"
var a = 1
var text string

func list() {
fmt.Printf("Hi!!!!! \n")
}

func main() {
list()

}


That's all for now. Next we'll see how to write Fibonacci number program, which is homework for lesson 1

Saturday, November 14, 2009

Rob Pike about Go

This is the second video, that i can find in the web about Go language. This is an one hour video from a conference, where one of developers of Go making a presentation, which you can find in pdf format on Go home page (download).
You can watch presentation video on youtube or download mp4 hd file (1gb).
PS. Sorry that I dont put video here - width of site is too small.

The Go Programming Language Promo


The first Google Go promo video

Friday, November 13, 2009

fatal error: can't find import: fmt?

If you have those problem - it means that you should define $GOROOT, $GOOS and $GOARCH variables. And if you are very lazy (as me :) ) you'l need a bash script to define vars and compile source code. So create new file, for expample "compile" and add to it


#!/bin/bash
export GOROOT=/home/your-name/hg
export GOOS=linux
export GOARCH=386
8g main.go
8l main.8
./8.out
read -p "Press [enter] to continue..."



If script doesn't work - cher path to the bash (for me it's /bin/bash), path to /hg and architecture. Also if you have 64-bit x86 system - you should write instead 8 write 6. If 32-bit x86, and more - 8.
And don't forget put execution rights ot this file.

Familiar? Forget it!


If it's familiar to you - u should try Google Go language. As developers write - you will forget about killing time waiting for compile. For example If A.go depends on B.go depends on C.go:
- compile C.go, B.go, then A.go.
- to compile A.go, compiler reads B.o not C.o.
At scale, this can be a huge speedup.

"Hello world!" program on Go

Hello again :)

Now i will teach u to write our firs Hello World! program on Go language. And, i'm sure, that you like Go as it did I. So let's start!

So make file, and name it hello.go. Open it with any of text editors and paste (or write - as u want) those code:


package main

import fmt "fmt"


func main() {
fmt.Printf("Hello, world!\n");
}

and save it. Than in terminal enter (with command cd) into directory, where you save Hello World! file, and write in terminal:

8g hello.go
8l hello.8
./8.out


ATTENTION! If it didn't works instead 8 write 6. It's for the 64-bit x86 systems. If u have 32-bit x86, and more - it should work with 8.

You'r a cool Go programmer now ;) Wait for a new tutorials and don't forget to subscribe! :)

How to install Go (GoLang) compiler on Ubuntu

Now i want to write tutorial how to install GoLang compiler on Ubuntu (no matter what: it can be jaunty jackalope, karmic koala or even hardy heron). So lets start!

So at first step you should go into terminal and write
export GOROOT=/home/your_name/hg

This will write into var $GOROOT your path where Go will be installed. But dont make this dir (/hg) - program will make it.

Then you should define other vars:
export GOOS=linux
export GOARCH=386

NOTE! In var $GOARCH you should write your processor architecture! For example: export GOARCH=amd64 or GOARCH=arm

The next step will be creation of /bin folder and addind 777 permission for it. So in your folder (/home/name) create "bin" directory and in the terminal write
chmod 777 /home/your-name/bin
export GOBIN=/home/your-name/bin
export PATH=$PATH:/home/your-name/bin

If you do all the right way - you will see
GOBIN=/home/your-name/bin
GOARCH=386
GOROOT=/home/your-name/hg/
GOOS=linux

when you write
env|grep '^GO'
in the terminal.

Then you shoul fetch Go source files from repo. In this situation helps Mercurial.
sudo apt-get install mercurial
hg clone -r release https://go.googlecode.com/hg/ $GOROOT

The second line will recive source code.

As you know, Go was written on C language, so you need to install C compiler (gcc) to compile Go. So in terminal write:
sudo apt-get install bison gcc libc6-dev ed


Then the last two steps. Just write in terminal
cd $GOROOT/src
./all.bash

and wait. If you all the same way as i describe - you will see something like that:
--- cd ../test
n known bugs; 0 unexpected bugs


In the next post i help you to write your first programm on Go!

Hello world!

Hi people! This blog will be about new and very perspective programming language - Go or GoLang. This language was deleloped by Google to make easier work of programmists.

And now i want to write a few words about me.

My name is Basil (in my coutry it will be Vasyl) Melnychuck, I'm from Ukraine (NOT RUSSIA!!!), Lviv. Now I study in Lviv National University named after Ivan Franko, on electronics facultet. Now i write code on PHP and MySQL languages. That's all :)

PS. Sorry for mistakes, i dont know English good :)