How I learned Go Programming

Francis Sunday on September 02, 2017

Go is a relatively new programming language, and nothing makes a developer go crazier than a new programming language, haha! As many new tech i... [Read Full]
markdown guide
 
 

Hello Francis Sunday, I already have some experience in Go (I'm familiar with the syntax), I want to ask you what kind of projects did you build in order to become a better go developer?, I mean did you build APIs, Blogs, Just practice with the language?

 

Whilst learning Go, I built a lot of things, from APIs (Here's an article I wrote on it hakaselabs.github.io/2017/06/23/re...), to little command line applications, currently I've been using Go extensively with the Company I'm with, and also Practice Practice!!

 

You can always get in touch with me if you have any questions on Go, I'd be glad to help :)

 

Thanks a lot I'm learning and practicing with Go all the time too, but I didn't have the chance of using it in a real project. Cheers!

 

Nice article Francis! Have any thoughts on testing with Go? I had to change the structure of my application in order to write proper tests (which turned out to be worth it). I'm curious to know how your shop does it.

 

Thanks Hoffman, for testing, I use the testing package from the standard go library. In the nearest future I'd like to work on an easy testing framework, say something similar to Jasmine or mocha for Node.js

 

That's a motivating post, Francis.
For the folks who wanna learn Golang, here are community recommended golang tutorials that can be good next step post this article: hackr.io/tutorials/learn-golang

 
 

Hello Francis.

Great Article!!

I'm a Java Developer for some years, and I interested in Go for now.
I read in some articles that GO don't have a Virtual Machine behind and all the code is compiled to native code. This is true? If yes, which approach use to manage memory??

Thanks!!

 

Hi there, take a look at this text from the Go website, it'll be of more help to answer your question - golang.org/doc/faq#garbage_collection

 

Typo: GOOS-linux go build. I think you meant GOOS=linux go build.

 
 

I've started to learn Go, however am struggling with interfaces, particularly compared to how they work in dynamically typed languages like PHP, any tips?

 

Interfaces in OOP, enforce definition of some set of method in the class. By implementing interfaces, you are forcing any class to declaring some specific set of methods.

Interfaces in Go can be seen as named collections of method signatures.

For instance, a Geometry interface in go both Circles and Rectangles can implement the same Interface, but they must implement all the methods of that interface.

package main
import (
  "fmt"
  "math"
)

type geometry interface {
  area() float64
  perimeter() float64
}

type circle struct {
  radius float64
}

type rectangle struct {
  width, height float64
}

// implementing the interface methods

func (c circle) area() float64 {
    return math.Pi * c.radius * c.radius
}
func (c circle) perimeter() float64 {
    return 2 * math.Pi * c.radius
}

func (r rectangle) area() float64 {
  return r.width * r.height
}

func (r rectangle) perimeter() float64 {
  return 2*r.width + 2*r.height
}

// we can call methods that are in the named interface

func measure(g geometry) {
    fmt.Println(g)
    fmt.Println(g.area())
    fmt.Println(g.perimiter())
}

// The circle and rectangle struct types both implement the geometry
// interface so we can use instances of these structs as arguments 
// to measure

func main() {
  r := rect{width: 3, height: 4}
  c := circle{radius: 5}

  measure(r)
  measure(c)
}

Here's an awesome reference to learn more about Interfaces in Go jordanorelli.com/post/32665860244/...

 
 

It is said that Go doesn't have "generics" but these look pretty much like generics:

func (r rectangle) area()

func (c circle) area()

 

Cool. What do you think of nil?

resolve bad practices of others while keeping the good things.

I think optionals are safer than nil. What do you think?

 

Well technically that may be true, but I prefer to stick with nil I often opt-in for optionals though.. but its preference over standards most times for me.

 
 
 

Have been looking to learn Go for a short while now. This is enough motivation for me too start off. Thanks Francis

 
 
 

I see what you did there... not cool man, not cool at all, copying other peoples work. zemanta.github.io/

 

Hey Peter, sorry if mine looks similar to yours, this was inspired by that article, I should have placed a credit though, skipped my mind. Anyways I'll make an edit to this.

 

Hey Francis, please place a credit and link to Zemanta's tech blog in your post. Otherwise no worries, keep teaching others about Go!!
All the best in 2018!

 

Hey, thanks for great post. I've just found some bugs in first example, you can check my version here play.golang.org/p/D1V6irVthg

 

Good one. Thanks I started learning Go and will share it in my Tutlane tutorials section.

 
 

Im stuck on css and dont even trying to finish it)

 

Hilarious, remember if you're stuck somewhere, always ask someone, you'd get out of your problems in no time.

 

Nice article, people who want to learn golang can check the best go tutorials recommended by experts at letsfindcourse.com/golang

code of conduct - report abuse