A Programmer's Guide To Go With LiteIDE
Written by Mike James   
Thursday, 14 November 2013
Article Index
A Programmer's Guide To Go With LiteIDE
Date Structures and Types
Functions
Go Control

Google's system programming language Go is becoming more mature and easier to use. Now is a good time to try it out with LiteIDE to make it even easier.  

A Programmer's Guide To Go

  1. A Programmer's Guide To Go With LiteIDE
  2. A Programmer's Guide To Go Part 2 - Objects And Interfaces
  3. A Programmer's Guide To Go Part 3 - Goroutines And Concurrency

 

Part 1  Language Basics

Data, Types, Functions and Control

gorunsGo is an easy-to-use but surprisingly powerful language. You could call it a modern version of C, but read on and find out what you think of it for yourself.  It has a clean and simple structure that is said to be statically typed. but it behaves like a dynamically typed language. It also compiles to native code, but is as easy to work with as an interpreted language. 

The bottom line is that it's worth a look and this article tells you all you need to know to get started. In Part 2 we'll take a closer look at how Go deals with objects and concurrency.

Setup 

All you have to do to set up Go is to download the appropriate binary and extract it to the correct directory and set the Path to point to the location of the bin directory where all of the Go tools live. 

https://golang.org/dl/

If you are using OSX or Windows then there are installers that you can use that will add the appropriate path.

The Windows MSI installer works very well and it gives you an instantly working installation - I recommend using it.

By default it installs the system in C:\Go

 

install

 

You can check that you have a working system by creating a simple program:

package main
import "fmt"
func main() {
 fmt.Printf("hello world\n")
}

You can use NotePad or any plain text editor and save the file as hello.go. To run it you need to open a console and type:

go run hello.go

There are alsorts of things that can go wrong with this procedure but all minor. The first is that if you use NotePad make sure that the file name is Hello.go and not Hello.go.txt. You will also have to either change directory to where the file is stored or enter the complete path to hello.go. Eventually however it should all work. Notice that it can take a few seconds to compile the program before you see the message.

As an alternative you can move on to install LiteIDE and try running a program from there. 

LiteIDE isn't essential for creating Go programs and you will hear programmers saying that it isn't necessary - all you need is an editor. This is true but for the casual programmer an IDE makes getting started easier and once you use LiteIDE you will quickly find that it makes you much more productive.

The only downside is that there is virtually no documentation for using LiteIDE. 

All you have to do is download a tarball or a zip from

https://sourceforge.net/projects/liteide/

and unpack it to a suitable folder.

 

If you are using Windows you will need a copy of 7zip to unpack it. You can unpack the program to any folder and it seems to work perfectly but one obvious place to store the liteide folder is within c:\go.

Of course with such minimal installation you don't get a shortcut to run the program so simply open c:\go\liteide\bin and find liteide.exe and create a shortcut or drag it to the taskbar or whatever you find useful.

When you run LiteIDE you will see a welcome screen with some useful links. 

 

liteidewelcome

 

You can worry about all the features of LiteIDE later. For the moment let's just get a simple Go program running. 

Select File New, from the menu or the New Button in the Welcome screen and in the dialog box that appears select Go1 Command Project. This creates a Go command line project for you in the C:/Go/src directory for you. If you give the project the name Hello it will create the files in C:/Go/src/Hello. 

 

newproject

 

The project template creates the Files, main.go, and doc.go in the project directory and the main.go file contains:

 

// Hello project main.go
package main
import (
    "fmt"
)
func main() {
    fmt.Println("Hello World!")
}

You can run the program using the blue Build and Run button marked BR in the toolbar. You can find a range of commands relating to building and running a program in the Build menu option and by dropping down the B and BR button menus.  

If you run the program you can see the result in the Build Output window at the bottom.

 

buildoutput

 

If this doesn't work the only possibilities are that you haven't created a default command line project or the Path is incorrectly set. 

There are many other feature in LiteIDE that you can explore but now you have enough to put Go though its paces. 

Variables And Simple Data Types

Go has all of the primitive data types you might expect from uint8 to float64.

  • uint8  unsigned 8-bit integers (0 to 255)
  • uint16 unsigned 16-bit integers (0 to 65535)
  • uint32 unsigned 32-bit integers (0 to 4294967295)
  • uint64 unsigned 64-bit integers (0 to 18446744073709551615)

  • int8  signed 8-bit integers (-128 to 127)
  • int16 signed 16-bit integers (-32768 to 32767)
  • int32 signed 32-bit integers (-2147483648 to 2147483647)
  • int64 signed 64-bit integers (-9223372036854775808 to 9223372036854775807)

  • float32  IEEE-754 32-bit floating-point numbers
  • float64  IEEE-754 64-bit floating-point numbers

  • complex64  complex numbers with float32 real and imaginary parts
  • complex128  complex numbers with float64 real and imaginary parts

  • byte alias for uint8
  • rune alias for int32

The big surprise is that it supports a complex numeric type:

var z complex64
z = 1.0 + 2.0i
fmt.Println(z)

And if you are wondering what a rune is then the mystery is solved once you know that t rune is used to store a Unicode code point. In other words, rune is Go's equivalent of a character type. 

You can also make use of uint, int and uintptr which are machine dependent integers with either 32 or 64 bits. 



Last Updated ( Thursday, 04 July 2019 )