miércoles, 29 de octubre de 2014

Mi first post on Go

As Go is gaining some popularity...I decided to give it a try...and sure...the fact that Ken Thompson is one of the three main designers of the language helped as well -:P

In order to learn I'm reading the book An Introduction to Programming in Go so expect a book review soon...

Now...my first impression of Go is that is basically C/C++ without the makeup...meaning...take out some nasty and weird features and you have yourself the Go programming language...

Go is supposed to be compiled, concurrent, imperative and structured.

Anyway...C++ was one of the first languages I ever learned so learning Go feels like going back home for a while...

For sure...the best way to learn a new language is to code something...so again I start by building something simple like the Fibonacci number generator based on Haskell code from another post...

package main

import ( "fmt"
   "strconv" )

func main() {
 fmt.Print("Enter a number: ")
 var num int
 fmt.Scanf("%d", &num)
 fmt.Print(fib(num, 0, 1))

func fib(num int, a int, b int) string{
 var result string
 if a > 0 && num > 1 {
  result += strconv.Itoa(a+b) + " " + fib(num-1, a+b, a)
 } else if a == 0 {
  result = strconv.Itoa(a) + " " + strconv.Itoa(b) + 
                             " " + strconv.Itoa(a+b) + 
                             " " + fib(num-1, a+b, b)
 return result

When we run it...we're going to see this -:)


Development Culture.