avatarBennett Garner

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2418

Abstract

alized in just a few minutes.</p><p id="37a6">From there, immediately try to start building something on your own.</p><p id="10ae">Even if it’s the simplest program ever. The code you write on your own will teach you way more than any tutorial you might follow.</p><p id="c400">You’re already building the muscle of independence. You don’t <i>need</i> the tutorial. You can solve problems on your own!</p><h1 id="70c4">Start building</h1><p id="a7fa">When I wanted to start building something on my own in Go, I looked around for a fun problem to tinker with.</p><p id="d6bc">A friend and I were joking around about rearranging the letters in our names. So, I thought — “I can write a program to give all the possible permutations of my name!”</p><p id="ae65">This is pretty simple string manipulation, but it’s a perfect first project for learning go because there are for loops, if statements, different data types, and recursion.</p><p id="d7ad">First, I searched the internet for an algorithm I could use to generate permutations. I found <a href="https://en.wikipedia.org/wiki/Heap%27s_algorithm">Heap’s Algorithm</a>, which seemed perfect & the Wikipedia page already has a helpful implementation in pseudo-code.</p><p id="7c4c">Now, I just needed to port the Wikipedia implementation to Go, using what I’d already learned!</p><h1 id="3639">My implementation</h1><p id="1e86">So, here’s my first Go program that I wrote from scratch.</p><p id="6780">It took a lot of searching for answers online. I hit a bunch of errors, and since I’m new to Go I didn’t always know what they meant. But I wrote this iteratively, myself, and learned a ton along the way.</p><p id="1b7f">Much more than I would have following a tutorial.</p><div id="4f2e"><pre><span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> ( <span class="hljs-string">"fmt"</span> <span class="hljs-string">"strings"</span> )

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> { names := <span class="hljs-string">"bennett"</span> letters := strings.Split(names, <span class="hljs-string">""</span>) heapPermutation(letters, <span class="hljs-built_in">len</span>(letters)) }

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">heapPermutation</span><span class="hljs-params

Options

">(s []<span class="hljs-type">string</span>, n <span class="hljs-type">int</span>)</span></span> []<span class="hljs-type">string</span> { <span class="hljs-keyword">if</span> n == <span class="hljs-number">1</span> { fmt.Println(strings.Join(s, <span class="hljs-string">""</span>)) <span class="hljs-keyword">return</span> s }

<span class="hljs-keyword">for</span> i := <span class="hljs-number">0</span>; i < n; i++ { heapPermutation(s, n<span class="hljs-number">-1</span>)

<span class="hljs-keyword">if</span> n&<span class="hljs-number">1</span> != <span class="hljs-number">0</span> { s[<span class="hljs-number">0</span>], s[n<span class="hljs-number">-1</span>] = s[n<span class="hljs-number">-1</span>], s[<span class="hljs-number">0</span>] } <span class="hljs-keyword">else</span> { s[i], s[n<span class="hljs-number">-1</span>] = s[n<span class="hljs-number">-1</span>], s[i] } } <span class="hljs-keyword">return</span> s }</pre></div><p id="0972">If you want to try it out & play with it — here it is in the <a href="https://play.golang.com/p/7MGh-vLb5To">Go playground</a>.</p><h1 id="5f5d">The takeaway</h1><p id="a0b9">Tutorials are a terrible way to learn to code.</p><p id="0cb9">You’ll learn much faster as soon as you can stop doing tutorials & start building something real on your own.</p><p id="387b">The thing you build doesn’t have to be crazy impressive!</p><p id="d32e">My first project in Go is only 30 lines long, and it just prints some strings. But now that I’ve built it, I feel much more confident in the language after just a few hours of tinkering.</p><p id="6850">So much more confident, that I think I’ll take a leap. My next step is building something with the <a href="https://gin-gonic.com/">Gin web framework</a>. I’m interested to see how webservers work in Go.</p><p id="7119">Whatever it is you’re trying to learn, you’re almost always better served when you skim through the tutorial and start building on your own as soon as possible.</p><h1 id="2035">Daily list</h1><p id="3963"><a href="https://bennettgarner.ck.page/medium"><b>Join my email list with 2,000 software developers to learn the habits & skills of top coders!</b></a></p><p id="0708"></p><p id="37d7"><i>P.S — <a href="https://bennettgarner.medium.com/membership">Join Medium for $5</a> : Access all of Medium + support me & others!</i></p></article></body>

How I’m learning Golang without tutorials

If you want to learn to code (or a new language) for real, you have to stop doing tutorials.

Tutorials are a trap. They’re a crutch that keep you reliant on new instructions. But as a software developer, your job is to build new things, solving problems that haven’t been encountered in the same way before.

This month, out of curiosity, I finally started learning Go.

I strongly believe that you get better as a developer when you learn a new language. Trying a new language expands the way you think about coding and approaches to problem solving.

So, how am I learning Go without tutorials?

Official docs

I’m going straight to the source to download Go, learn the commands to run it, and learn the basics of syntax.

https://go.dev/learn/

The official documentation is where I always start when I’m learning something new. I don’t want some random person’s blog. I want the official resource, so I know I’m learning the right way to do things.

Now, the official docs have tutorials & I do use them! But not in the way you might think…

Mostly, I click through the tutorials to look at code patterns. Sometimes, I’ll copy-paste code locally, run it, and then immediately start to change it to test my understanding.

I’m using the tutorial code as a starting point, but actively trying to break the tutorial. Don’t stay on the happy path. Instead, learn the limits.

The basics

Here’s all you need to start developing in a new language:

  1. Variable declaration
  2. Data types
  3. If/else
  4. Loops

The good news is these 4 things are very quick to learn for any language. Sure, there are lots of details that will take time to learn. But you can have the basics internalized in just a few minutes.

From there, immediately try to start building something on your own.

Even if it’s the simplest program ever. The code you write on your own will teach you way more than any tutorial you might follow.

You’re already building the muscle of independence. You don’t need the tutorial. You can solve problems on your own!

Start building

When I wanted to start building something on my own in Go, I looked around for a fun problem to tinker with.

A friend and I were joking around about rearranging the letters in our names. So, I thought — “I can write a program to give all the possible permutations of my name!”

This is pretty simple string manipulation, but it’s a perfect first project for learning go because there are for loops, if statements, different data types, and recursion.

First, I searched the internet for an algorithm I could use to generate permutations. I found Heap’s Algorithm, which seemed perfect & the Wikipedia page already has a helpful implementation in pseudo-code.

Now, I just needed to port the Wikipedia implementation to Go, using what I’d already learned!

My implementation

So, here’s my first Go program that I wrote from scratch.

It took a lot of searching for answers online. I hit a bunch of errors, and since I’m new to Go I didn’t always know what they meant. But I wrote this iteratively, myself, and learned a ton along the way.

Much more than I would have following a tutorial.

package main

import (
 "fmt"
 "strings"
)

func main() {
 names := "bennett"
 letters := strings.Split(names, "")
 heapPermutation(letters, len(letters))
}

func heapPermutation(s []string, n int) []string {
 if n == 1 {
  fmt.Println(strings.Join(s, ""))
  return s
 }

 for i := 0; i < n; i++ {
  heapPermutation(s, n-1)

  if n&1 != 0 {
   s[0], s[n-1] = s[n-1], s[0]
  } else {
   s[i], s[n-1] = s[n-1], s[i]
  }
 }
 return s
}

If you want to try it out & play with it — here it is in the Go playground.

The takeaway

Tutorials are a terrible way to learn to code.

You’ll learn much faster as soon as you can stop doing tutorials & start building something real on your own.

The thing you build doesn’t have to be crazy impressive!

My first project in Go is only 30 lines long, and it just prints some strings. But now that I’ve built it, I feel much more confident in the language after just a few hours of tinkering.

So much more confident, that I think I’ll take a leap. My next step is building something with the Gin web framework. I’m interested to see how webservers work in Go.

Whatever it is you’re trying to learn, you’re almost always better served when you skim through the tutorial and start building on your own as soon as possible.

Daily list

Join my email list with 2,000 software developers to learn the habits & skills of top coders!

P.S — Join Medium for $5 : Access all of Medium + support me & others!

Software Development
Coding
Programming
Golang
Python
Recommended from ReadMedium