Skip to main content

Say Hello World with Golang


  • We will start with the traditional "Hello World" program which will appear in 1978 in the C programming language.
  • C language influenced directly on Go.


  • We assume that you have programmed in one or more languages whether compiled like c, c++, java or interpreted python, ruby, javascript.
  • Go is compiled language.
  • The Go toolchain converts source code. These toolchain accessed by a single command called go and multiple subcommands (run, build).
  • $ go run hello_world.go
  • prints -
    • Hello World, 世界
  • Go handles Unicode. so it can process text in all languages.
  • If the program is more than a one-shot experiment means we run a file any time without processing used build subcommand.
  • $ go build hello_world.go
  • This creates an executable binary file called hello. that file can run anywhere without further processing 
  • $ ./hello_world
    • Hello World, 世界
  • Let's talk about the program :
    • Packages: Go code is organized into packages modules which are similar to libraries and modules in other languages.
    • Go packages consists of one or more .go source file in a single directory
    • Each source file begins with package declaration( package main) and another package which is followed by a file import.
    • package main is special. it defined a standalone executable program, not a library
Gofmt :
  • Gofmt is a tool that automatically formats go source code.
Usage : 
gofmt [flags] [path ...]

Why Gofmt :
  1. Easier to write: never worry about minor formatting concern while hacking away,
  2. Easier to read: when all code looks the same you need not mentally convert others formatting style into something you can understand.
  3. Easier to maintain: mechanical changes to the source don't cause unrelated changes to the file's formatting; diffs show only the real changes.
  4. uncontroversial: never have a debate about spacing or braces ever again!
Note :
On the survey of Go package Found that about 70% of them are formatted according to gofmt's rules.
This was more than expected.
To format your code, you can use the gofmt tool directly :
   - $gofmt -w hello_world.go

Command Line Arguments

Command line arguments is a parameter supplied to the program when it is involved.




Reference :
  1. https://blog.golang.org/
  2. https://tour.golang.org/welcome/1





Comments

Post a Comment

Popular posts from this blog

THE ORIGINS OF GOLANG

“Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.” - golang.org Go (as referred as Golang) was convinced in September 2007 by Robert Griesemer, Rob Pike, and Ken Thompson, and was announced on 10 November 2009. Go borrows and adapts good ideas from many others languages, and avoiding some features that have led to complexity and unreliable code. Golang facilities for concurrency are the new and efficient feature and its approach to data abstraction and object-oriented programming is unusually flexible, and it has automatic memory management (gc). Go is specially build infrastructure like network servers, and tools and systems for programmers. Go is an open-source project which is already mentioned in quotes, so for the source code for its compiler, libraries, and tools is freely available to anyone. Go runs on Unix like systems - Linux, FreeBSD, OpenBSD, Mac OS X and on Plan 9 and Micr...

Asymptotic Notation

What is Asymptotic Notation? Asymptotic Notations are algorithms growth rate all languages allow us to analyze algorithms running time by identifying its behavior as an input size for the algorithms increases. Common Rate of Growth Comparing some efficiency of algorithms. We need some common growth rates. Let's assume n in the size of input and c some constant. The following are the common rate of growth : Logarithmic Function - log n  Linear Function - an + b Quadratic Function - an^2 + bn + c Polynomial Function - an^z + ... + an^2 + a*n^1 + a*n^0, where z is some constant Exponential Function - a^n, where a is some constant When analyzing function considering the higher limit part of the function i.e linear function an + b here n is a large value with constant a. Logarithmic - log n  Linear  - n  Quadratic  - n^2 Polynomial - n^z, where z is some constant Exponential - a^n, where a is some constant Classif...