Starting new post for learning Golang
This commit is contained in:
parent
63aa25dd06
commit
0a7dee69b9
@ -19,7 +19,7 @@ theme = "blackburn"
|
||||
disqus = "jakewindle-life"
|
||||
# CSS name for highlight.js
|
||||
highlightjs = "androidstudio"
|
||||
highlightjs_extra_languages = ["yaml", "julia"]
|
||||
highlightjs_extra_languages = ["yaml", "julia", "go"]
|
||||
dateFormat = "02 Jan 2006, 15:04"
|
||||
# Include any custom CSS and/or JS files
|
||||
# (relative to /static folder)
|
||||
@ -62,6 +62,7 @@ theme = "blackburn"
|
||||
|
||||
# SNS microblogging
|
||||
|
||||
|
||||
# SNS career oriented
|
||||
linkedin = "windlejacob12"
|
||||
|
||||
|
57
content/post/learning-go-pointer-receivers.md
Normal file
57
content/post/learning-go-pointer-receivers.md
Normal file
@ -0,0 +1,57 @@
|
||||
---
|
||||
title: "Learning Go: Methods and Pointer Receivers"
|
||||
date: 2017-12-29T10:46:08-05:00
|
||||
draft: true
|
||||
tags: ["golang", "learning"]
|
||||
---
|
||||
|
||||
# I gotta get Go-ing with this language
|
||||
|
||||
Being in the position I am, I've worked with almost nothing but exclusively interpreted languages, namely Ruby and Python.
|
||||
Both of these are great tools to have to solve problems and to solve them quickly. It is easy to pick up an idea and get
|
||||
a prototype going in Python or Ruby due to not having to run any compilation, code changes can be tested instantly often by
|
||||
just rerunning the interpreter. However, this can be a problem when programs get large. I've been a part of projects
|
||||
where there are hundreds of thousands of lines of Ruby and Python code where changes to some backend call can cause a ten second
|
||||
difference in the load time of the frontend client.
|
||||
|
||||
![Image](/img/post/golang.gif)
|
||||
|
||||
|
||||
People much smarter than me at Google have created and actively develop the programming language Go, which is a compiled language
|
||||
that does a lot of cool things out of the box. Knowing how many problems I've had in development that could be potentially solved by Go
|
||||
(and missing compilers which catch some nasty bugs before the software starts), I want to learn Go and blog about cool things I find or cool
|
||||
things I do with it.
|
||||
|
||||
## Methods in Golang?
|
||||
|
||||
Yes, and this comes from old OOP concepts of message passing to objects. These methods are a neat way to be able to add functionality to your
|
||||
types you define in Go. If you are like me coming from OOP languages, methods are a very helpful construct.
|
||||
|
||||
So we've got these people right? And people in this universe are very simple. All they have to identify them is their name, their astrological sign
|
||||
and their disposition.
|
||||
|
||||
```go
|
||||
type Person struct { name, sign, disposition String }
|
||||
```
|
||||
|
||||
Now a person's name may not change, not their sign, but what about their disposition? I'd say my average day is an emotional rollercoaster! Only kidding,
|
||||
but we need a way to operate on the person's disposition, let's say based on weather.
|
||||
|
||||
```go
|
||||
// Actually a pointer receiver
|
||||
func (p *Person) AlterDisposition (weather string) {
|
||||
switch weather {
|
||||
case 'rainy':
|
||||
p.disposition = "sad"
|
||||
case 'sunny':
|
||||
p.disposition = "happy"
|
||||
default:
|
||||
p.disposition = "meh"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
That's a funky syntax for this
|
||||
|
||||
|
||||
|
BIN
static/img/post/golang.gif
Normal file
BIN
static/img/post/golang.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 148 KiB |
Loading…
Reference in New Issue
Block a user