2020-10-06 Update

Time for another update.

I have not spent any time at all on the Go tutorials in the past few weeks.

One reason is that I am finally reading the Dune books. I tried to read it years ago, but did not get very far; I probably got a copy from the library and put off reading it.

I saw the David Lynch film, which I still think is bizarre. Patrick Stewart leading men into battle with a pug? Sting in a metal diaper? I did not see this; I was not here. The 2001 and 2003 adaptations were pretty good. At some point I want to watch Jodorowsky’s Dune.

Just to pick a few nits: The pug shows up several times with multiple members of House Atreides before Patrick Stewart carries it to Sardaukar oblivion. There is no mention of said dog in the book. And “weirding” in the book has NOTHING to do with sound. When David Lynch tries to blame the studio for meddling, he is full of it.

I was on IMDB after binge-watching Friends for the 5 millionth time, and I saw a preview for a new adaptation of Dune. I know the whole point of previews is to make you say, “This will be amazing”, but I think this will be amazing. Ronan Dex as Duncan Idaho; who could ask for more? Taking  two films to cover the first novel is a wise decision.

So I got all six of the original novels and started going through them. I am done with Dune, and have started Dune Messiah. I am honestly surprised that the Dune series became as popular as they have. I know that any franchise just sticks you in the middle of its world/universe, but that is REALLY true of Dune. The glossary at the end really helped. I am reading these near my laptop so I can look up terms I do not know on the Dune Wiki.

Back to Go:

One thing that was bugging me about going through the Go tutorials is that my hand started hurting from all the typing. Then my keyboard started dying; unlike most emacs users, it was not my wrist that gave out, it was my left control key. So I got a new Insignia keyboard. These things are like butter. I went to Best Buy and got three more.

Plus, maybe I just don’t like Go. I can see why functional programmers say they are sick of writing for loops. While it’s great that Go functions can return two values so you can catch potential problems, I am also getting sick of writing “if err != nil”. And I do not like that Pluralsight instructors do not spend more time including automated tests. I am not a unit testing fundamentalist, but tests are always good.

Granted, one of the creators of Go is Ken Thompson. Along with Dennis Ritchie  and Brian Kernighan he invented Unix and C at Bell Labs in the late 1960s-early 1970s. Another creator is Rob Pike who came to Bell Labs later. (Go has a third creator: Robert Griesemer; I never heard of him, but he has KT’s stamp of approval; who am I to argue?) I don’t know if you could write an OS in C, but it seems like Go is C 2.0. Given who created it, this is not a surprise.

I am also seeing the appeal of Lisp a bit more now. Lisp is more uniform. In a language with functions and primitives, things happen in different orders, particularly math. “2.add( 2 )” is more typing than “2 + 2”, but “2.add( 2 )” is closer to how most functions are written in Go. (“add( 2, 2 )” is another way to do it.) Maybe that is why Lisp is so jarring at first; it’s not just the parentheses, it’s that everything is different. This is not specific to Go.

There are a lot of things that I like. For example, the “defer” keyword is a great idea. If you open a file, database, or some other resource, you put a statement or block starting with the word “defer” right after it to close the resource.

	file, err := os.Open( "test.txt" )
	if err != nil {
		fmt.Println( err )
	}
	defer file.Close()

The defer statements/blocks are not executed when the function is executed; all the defer blocks will be executed when the function they are in is done executing. I think the defer statements/blocks get put into small functions and are put on the stack at run-time. This backwards post-function execution happens even if the function has an error. It looks like a more elegant way to do try/catch/finally, and since you put the “defer” to close right after the open, you could potentially prevent all resource-related memory issues. Not closing database connections and file handles seems to be one of the major sources of memory issues in Java, although try-with-resources does help.

When I was at Bank Of America, there was a C/C++ programmer who gave a tip on memory management: Allocate everything you need at the beginning of a function, and de-allocate it all at the end. For a while his main responsibility was re-factoring in-house apps that crashed a lot because a lot of devs were bad at managing memory.

Also, the idea of making fast apps with low memory usage is very appealing. I will get back to Go soon.

You’re welcome.

Image from the Askew Gospel, a 12th century manuscript housed at the British Library; image assumed allowed under Public Domain.