Commit d2460755 authored by Rob Muhlestein's avatar Rob Muhlestein 🎧

head first go added

parent ba0fcb7c
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>README</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
</head>
<body>
<p>TODO</p>
</body>
</html>
......@@ -25,7 +25,7 @@ The amount of indentation has *nothing* to do with coding in C until you do it d
### C Versions and Compilers
*Just use `gcc -std=c99`.*
*Just use `gcc --standard=c11 --pedantic`.*
The `gcc` compiler has been the standard for more than thirty years. C99 is the most widely supported version of C even though the standard itself is at C2X now. Most projects and documentation will be using C99.
......
CC=gcc
CFLAGS=-std=c11 --pedantic
all: hello
install: hello
mv hello ~/.local/bin
clean:
rm hello
#include <stdio.h>
int main() {
printf("Hello, World!\n");
}
......@@ -38,7 +38,7 @@
</ul>
<p>The amount of indentation has <em>nothing</em> to do with coding in C until you do it differently than <em>everyone</em> else on a collaborative project. That is all you really need to know about styles. Do it the way the project requires, and if it is your project do it however you like. You might even find simply two-space indentation is just fine.</p>
<h3 id="c-versions-and-compilers">C Versions and Compilers</h3>
<p><em>Just use <code>gcc -std=c99</code>.</em></p>
<p><em>Just use <code>gcc --standard=c11 --pedantic</code>.</em></p>
<p>The <code>gcc</code> compiler has been the standard for more than thirty years. C99 is the most widely supported version of C even though the standard itself is at C2X now. Most projects and documentation will be using C99.</p>
<h4 id="why-not-clang">Why not <code>clang</code>?</h4>
<p>The <code>clang</code> tool might boast faster <em>perceived</em> compilation times, color terminal support, and very verbose errors but strictly speaking <code>clang</code> isn’t even a true C compiler. It creates a small bit of binary code that is combined with something called the Low-Level Virtual Machine or LLVM. This is exactly what other LLVM languages do as well (Rust, Crystal, and Julia). To give you a sense of this, the first LLVM was created with <code>gcc</code>, the main Linux compiler. Considering that the main reason you are learning C at this point is to understand how languages work and interact with the underlying operating system and machine it is in our best interests to leave out the LLVM, which robs you of the opportunity to actually compile to machine code. # RWX C Coding Style</p>
......
......@@ -3,12 +3,120 @@ title: Head First Go
Title: Head First Go
---
*Head First Go* is currently the best Go programming language book for beginners. It is available for [purchase](https://www.amazon.com/Head-First-Go-Jay-McGavren/dp/1491969555) and online as PDF for free (although this is illegal in most countries).
Even though *Head First Go* is *very* out of date it is currently the best Go programming language book for beginners. It is available for [purchase](https://www.amazon.com/Head-First-Go-Jay-McGavren/dp/1491969555) and online as PDF for free (although it is difficult to find and illegal in most countries).
## But First ...
## Before You Begin
There are a few things you should read before jumping into the book because it is rather out of date. Thankfully most of the content is still relevant but it is *particularly* important that you have a handle on `go mod init ...`. Please read the following thoroughly before getting started:
Although *Head First Go* assumes very little about your background (only that you "understand folders and files, how to open a terminal app, and how to use a simple text editor") these annotations assume you have *completed* [Basic Linux Proficiency](/blip-boost/) (or have learned the skills and concepts some other way). This means that you should ...
* Be running Linux Debian
* Know the Bash command line
* Be able to edit files with Vim
* Understand basic *data types*
* Know what a *pointer* is
* Be comfortable coding in JavaScript
* Know what *interpreted* means
* Have programmed in C from CLI
* Know what *compiled* means
* Understand *CPU*, *RAM*, and storage
* Know basic `git` commands
* Have a Git hosting account (GitLab)
*This is not a comprehensive list. See the [BLiP Boost](/blip-boost/) for more details.*
These higher expectations are to prepare you for *real* work using the language rather than just doing the minimum to learn it. We can proceed much more quickly through the Go book because you should *already* have mastered programming and are now just learning another language.
### Install the Latest Go
First check to see that you don't already the right version of Go installed:
```sh
go --version
```
The current version (as of April 23, 2020) is 1.14.2.
You can certainly following the [installation instructions](https://golang.org/doc/install) on the Go page. Or you can add this little script to manage your Go version installation like any other package on your system. Keep in mind that although this PPA is non-standard and not supported by Go officially it is used by thousands.
```sh
#!/bin/sh
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update
sudo apt install golang-go
```
:::callout-fyi
If you absolutely have no other option you can always just create a Golang project on [REPL.it](https://repl.it).
:::
### Getting Vim Ready for Go Coding
The [`fatih/vim-go`](https://github.com/fatih/vim-go) plugin is pretty standard albeit annoying at times. Don't forget to Install all the `vim-go` dependencies with `:GoInstallBinaries` from within a Vim session if you choose to use the following:
```vim
" Install the Plug plugin manager if not detected.
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall
endif
" If Plug plugin manager detected then load the plugins and configure
if filereadable(expand("~/.vim/autoload/plug.vim"))
call plug#begin('~/.vimplugins')
" ... other plugins here
Plug 'fatih/vim-go'
call plug#end()
let g:go_fmt_fail_silently = 0 " let me out even with errors
let g:go_fmt_command = 'goimports' " autoupdate import
let g:go_fmt_autosave = 1 " autosave on updates
" Otherwise fallback to some safe backups
else
autocmd vimleavepre *.go !gofmt -w % " backup if fatih fails
endif
```
## Chapter One: Let's Get Going: Syntax Basics
Hello world is hello world. Nothing fancy to see there.
Use the Go community convention of naming the file with the `func main()` in it `main.go` so you can find it easier.
Here's a version that introduces emojis as *runes* as well as the `fmt.Printf()` function:
```go
package main
import (
"fmt"
"math"
"strings"
)
func main() {
fmt.Println(math.Floor(2.75))
fmt.Println(strings.Title("head first go"))
a := '🙂'
fmt.Printf("The letter '%c': %b\n", a, a)
}
```
<https://rwx.gg/head-first-go/chapter1/main.go>
TODO
## Frequently Asked Questions (FAQ)
Here are the most frequently asked questions about these annotations and the *Head First Go* book itself.
### Where can I get the PDF of the book?
Online. But using a PDF without having paid for the book is illegal in most countries (and some would argue even *with* having purchased the book). Please do not ask anyone from the rwx.gg team to provide you with a PDF. If you want one you'll need to find one on your own.
### Can I use Visual Studio Code (VSCode)?
Using anything but `vim` from the `bash` command line is strongly discouraged for reasons covered in the [BLiP Boost](/blip-boost/). But you can certainly use VSCode (or any editor for that matter) if you really want to. No time is spent explaining how so please *do not ask how to configure it during sessions*.
package main
import "fmt"
func main() {
fmt.Println("Hello, Go!")
}
package main
import (
"fmt"
"math"
"strings"
)
func main() {
fmt.Println(math.Floor(2.75))
fmt.Println(strings.Title("head first go"))
a := '🙂'
fmt.Printf("The letter '%c': %b\n", a, a)
}
......@@ -12,6 +12,68 @@
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
......@@ -21,7 +83,87 @@
<header id="title-block-header">
<h1 class="title">Head First Go</h1>
</header>
<p><em>Head First Go</em> is currently the best Go programming language book for beginners. It is available for <a href="https://www.amazon.com/Head-First-Go-Jay-McGavren/dp/1491969555">purchase</a> and online as PDF for free (although this is illegal in most countries).</p>
<h2 id="go-boost">Go Boost</h2>
<p>Even though <em>Head First Go</em> is <em>very</em> out of date it is currently the best Go programming language book for beginners. It is available for <a href="https://www.amazon.com/Head-First-Go-Jay-McGavren/dp/1491969555">purchase</a> and online as PDF for free (although it is difficult to find and illegal in most countries).</p>
<h2 id="before-you-begin">Before You Begin</h2>
<p>Although <em>Head First Go</em> assumes very little about your background (only that you “understand folders and files, how to open a terminal app, and how to use a simple text editor”) these annotations assume you have <em>completed</em> <a href="/blip-boost/">Basic Linux Proficiency</a> (or have learned the skills and concepts some other way). This means that you should …</p>
<ul>
<li>Be running Linux Debian</li>
<li>Know the Bash command line</li>
<li>Be able to edit files with Vim</li>
<li>Understand basic <em>data types</em></li>
<li>Know what a <em>pointer</em> is</li>
<li>Be comfortable coding in JavaScript</li>
<li>Know what <em>interpreted</em> means</li>
<li>Have programmed in C from CLI</li>
<li>Know what <em>compiled</em> means</li>
<li>Understand <em>CPU</em>, <em>RAM</em>, and storage</li>
<li>Know basic <code>git</code> commands</li>
<li>Have a Git hosting account (GitLab)</li>
</ul>
<p><em>This is not a comprehensive list. See the <a href="/blip-boost/">BLiP Boost</a> for more details.</em></p>
<p>These higher expectations are to prepare you for <em>real</em> work using the language rather than just doing the minimum to learn it. We can proceed much more quickly through the Go book because you should <em>already</em> have mastered programming and are now just learning another language.</p>
<h3 id="install-the-latest-go">Install the Latest Go</h3>
<p>First check to see that you don’t already the right version of Go installed:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1"></a><span class="ex">go</span> --version</span></code></pre></div>
<p>The current version (as of April 23, 2020) is 1.14.2.</p>
<p>You can certainly following the <a href="https://golang.org/doc/install">installation instructions</a> on the Go page. Or you can add this little script to manage your Go version installation like any other package on your system. Keep in mind that although this PPA is non-standard and not supported by Go officially it is used by thousands.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1"></a><span class="co">#!/bin/sh</span></span>
<span id="cb2-2"><a href="#cb2-2"></a></span>
<span id="cb2-3"><a href="#cb2-3"></a><span class="fu">sudo</span> add-apt-repository ppa:longsleep/golang-backports</span>
<span id="cb2-4"><a href="#cb2-4"></a><span class="fu">sudo</span> apt update</span>
<span id="cb2-5"><a href="#cb2-5"></a><span class="fu">sudo</span> apt install golang-go</span></code></pre></div>
<div class="callout-fyi">
<p>If you absolutely have no other option you can always just create a Golang project on <a href="https://repl.it">REPL.it</a>.</p>
</div>
<h3 id="getting-vim-ready-for-go-coding">Getting Vim Ready for Go Coding</h3>
<p>The <a href="https://github.com/fatih/vim-go"><code>fatih/vim-go</code></a> plugin is pretty standard albeit annoying at times. Don’t forget to Install all the <code>vim-go</code> dependencies with <code>:GoInstallBinaries</code> from within a Vim session if you choose to use the following:</p>
<pre class="vim"><code>&quot; Install the Plug plugin manager if not detected.
if empty(glob(&#39;~/.vim/autoload/plug.vim&#39;))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall
endif
&quot; If Plug plugin manager detected then load the plugins and configure
if filereadable(expand(&quot;~/.vim/autoload/plug.vim&quot;))
call plug#begin(&#39;~/.vimplugins&#39;)
&quot; ... other plugins here
Plug &#39;fatih/vim-go&#39;
call plug#end()
let g:go_fmt_fail_silently = 0 &quot; let me out even with errors
let g:go_fmt_command = &#39;goimports&#39; &quot; autoupdate import
let g:go_fmt_autosave = 1 &quot; autosave on updates
&quot; Otherwise fallback to some safe backups
else
autocmd vimleavepre *.go !gofmt -w % &quot; backup if fatih fails
endif
</code></pre>
<h2 id="chapter-one-lets-get-going-syntax-basics">Chapter One: Let’s Get Going: Syntax Basics</h2>
<p>Hello world is hello world. Nothing fancy to see there.</p>
<p>Use the Go community convention of naming the file with the <code>func main()</code> in it <code>main.go</code> so you can find it easier.</p>
<p>Here’s a version that introduces emojis as <em>runes</em> as well as the <code>fmt.Printf()</code> function:</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode go"><code class="sourceCode go"><span id="cb4-1"><a href="#cb4-1"></a><span class="kw">package</span> main</span>
<span id="cb4-2"><a href="#cb4-2"></a></span>
<span id="cb4-3"><a href="#cb4-3"></a><span class="kw">import</span> (</span>
<span id="cb4-4"><a href="#cb4-4"></a> <span class="st">&quot;fmt&quot;</span></span>
<span id="cb4-5"><a href="#cb4-5"></a> <span class="st">&quot;math&quot;</span></span>
<span id="cb4-6"><a href="#cb4-6"></a> <span class="st">&quot;strings&quot;</span></span>
<span id="cb4-7"><a href="#cb4-7"></a>)</span>
<span id="cb4-8"><a href="#cb4-8"></a></span>
<span id="cb4-9"><a href="#cb4-9"></a><span class="kw">func</span> main() {</span>
<span id="cb4-10"><a href="#cb4-10"></a> fmt.Println(math.Floor(<span class="dv">2</span><span class="fl">.75</span>))</span>
<span id="cb4-11"><a href="#cb4-11"></a> fmt.Println(strings.Title(<span class="st">&quot;head first go&quot;</span>))</span>
<span id="cb4-12"><a href="#cb4-12"></a> a := &#39;🙂&#39;</span>
<span id="cb4-13"><a href="#cb4-13"></a> fmt.Printf(<span class="st">&quot;The letter &#39;%c&#39;: %b</span><span class="ch">\n</span><span class="st">&quot;</span>, a, a)</span>
<span id="cb4-14"><a href="#cb4-14"></a>}</span></code></pre></div>
<p><a href="https://rwx.gg/head-first-go/chapter1/main.go" class="uri">https://rwx.gg/head-first-go/chapter1/main.go</a></p>
<p>TODO</p>
<h2 id="frequently-asked-questions-faq">Frequently Asked Questions (FAQ)</h2>
<p>Here are the most frequently asked questions about these annotations and the <em>Head First Go</em> book itself.</p>
<h3 id="where-can-i-get-the-pdf-of-the-book">Where can I get the PDF of the book?</h3>
<p>Online. But using a PDF without having paid for the book is illegal in most countries (and some would argue even <em>with</em> having purchased the book). Please do not ask anyone from the rwx.gg team to provide you with a PDF. If you want one you’ll need to find one on your own.</p>
<h3 id="can-i-use-visual-studio-code-vscode">Can I use Visual Studio Code (VSCode)?</h3>
<p>Using anything but <code>vim</code> from the <code>bash</code> command line is strongly discouraged for reasons covered in the <a href="/blip-boost/">BLiP Boost</a>. But you can certainly use VSCode (or any editor for that matter) if you really want to. No time is spent explaining how so please <em>do not ask how to configure it during sessions</em>.</p>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment