Up and Running

Features


The first thing I want to do in learning about Go is to find out why people like it. A quick search gives me this list:

  • Compiles fast
  • Runs fast
  • Distributable
  • Simplicity(? )
  • Multicore
  • Concurrent
  • GC ugh
  • It’s Google ugh

Honestly, this is a pretty generic list that most languages tout. Think of it this way, no programming language would promote itself as being:

  • Slow
  • Runs on one machine
  • Obfuscated code
  • Will only run on a dedicated CPU.

So, I tend to take the features in a programming language as being all relative–relative to other programming languages, and not as absolutes. To me, the simplest programming language is BASIC, or FORTH. Multicore to me is less important than multiprocessor–I spent my professional career avoiding threads and worrying about cores. Distribute over complete CPUs. GC is fast nowadays, but it’s not really a feature, per se, if everyone[sic] has one.

Google/Go, I should have seen this coming, but for some reason I didn’t realize Go is a Google language. Google is known for killing projects, and other nasty things. But, because Go is out-in-the-wild, this is less of a concern.

Trying it.



Now that I know a bit about it, let’s get it running.

Go has a website at
https://golang.org where you can download versions and try it out from the web browser. Let’s do that first since there is an example Hello World program already written for us. I see the “Open in Playground” button. Playgrounds are fun (unless you fall off the swing and land in a pile of broken glass). Let’s go swinging.

Click the ‘Open in Playground’ button.

I use the Playground’s text editor to make a simple change to the sample program.


Screen Shot 2021-01-01 at 10.24.04 AM 10.31.23 AM

Here are my first thoughts based on this sample program:

  • Wow, it’s Java! >snark<
  • Each program has to be in a package. I get it.
  • Each program needs a “main” for execution start. I get it.
  • Everything lowercase apart from function in Package(? )
  • No semicolons. I get it.

So, what I see the typical structure of a program is:

  1. package
  2. import
  3. functions (incl. required main).

Too bad I can’t call the
main Aslans (If you get it, you get it. There is a language, TAL, that allows you to attach a name to the main, and we always called it Aslans. )

Ok, let’s run it. I tap the Run button, and this is what I get:

Screen Shot 2021-01-01 at 10.24.04 AM


Cool! Everything worked. That’s not very interesting.

Errors


Let’s see what happens if I make a mistake. Here is my test and the corresponding output:

IMG_5378

This is pretty straight-forward. First is the program name (the Playground supplied it for us), the line and column number where the error occurred, and the error message. The Playground conveniently color-codes the error lines for us. Ok, decent, not ideal. I’d like the actual error highlighted, not just the line.

Installation


Playgrounds are fun, but we have to enter the real world. Let’s get Go running on my system. I’m going to be using a RaspberryPi Zero. Why? They are cheap and I can dedicate an entire machine (small as it is) to Go. The
https://golang.org site says you can get a download for Mac, Windows, and Linux. Hm. Pis are Linux, maybe there is an easier way than downloading and (probably) building from source code. I log into my Pi and type:

sudo apt-get install go

…nope. Doesn’t work. What if I try this:

sudo apt-get install golang

Bingo!

Unix lets you see the version. A quick search gives me this command:

go version

I try it. It works.

IMG_5379


Now, let’s type in the hello world program and see if I can get it to run. I fire up nano (my editor of choice) and soon have the code in a file I called prog.go. Another search tells me the command to run a program is:

go run

I type:

go run prog.go

IMG_5382

It works! Not exciting, but it works.

I have a working environment that I can now use to learn. That’s enough progress for now.


This site does not track your information.