2022-09-08 Writing Go code
God Speed You! Black Emperor is playing in the kitchen, the sound of cursed air planes can be heard, children shouting, cars driving. Iāve just had some self-made bread with cheese and now Iām drinking tea.
Hex Populate remains an interesting project, mainly for two reasons:
1. Itās my first and only real Go project.
2. Itās an online application without a web user interface.
Thatās right. It remains strictly available via SSH and SCP. You connect to it via SSH, and use it. When you save it, the files are only kept for as long as your connection remains active, so you need to copy the files to your computer using SCP before quitting.
Image 1 for 2022-09-08 Writing Go code
Iām currently learning about writing unit tests. š
Iām also starting to get the hang of how to use the `go doc` command. Very nice.
Things that I like, and that remind me of Perl:
- a command to read documentation
- a command to run tests
- a standardized way to write tests
- slices which feel like dynamic arrays
- maps
I think I could get used to writing the code.
Thereās white-space stuff that ends up being easy to understand. Basically, you can always replace a semicolon to end a statement with a newline, and you can add extra newlines if the preceding expression is sure to require more tokens, e.g. ending the line with an operator that requires another operand. This works surprisingly well. Itās better than C and Perl and not as bad as Python.
Hereās a thing I felt was annoying: initialising multidimensional arrays.
Hereās a think I like: `iota` automatically starts an enumeration. Types are simple to use and casting works.
Thereās probably lots of style issues with my code. Remember the case shorthands? camelCase, PascalCase, kebab-case, snake_case. I like kebab-case best because it works in Lisp, but when I canāt use it, I use snake_case, like in Perl. I think the Go people use camelCase for private names, oops. Since I donāt write a library, I havenāt had to use PascalCase ā thatās what they use for public names. Oh well.
If you check it out and notice issues, let me know. As I said, this is my first Go project.
ā#Programming ā#GoLang ā#Hex Populate
Comments
(Please contact me if you want to remove your comment.)
ā
Strangely enough, when assigning arrays these donāt get copied, even though blog posts say that this is how it works. Is this SEO destroying the utility of looking up code examples online? (Edit: this is a slice, not an array ā see below for more.)
In my particular case, I sometimes need a list of positions to go through, sorted by altitude. I have an array of positions but the index is meaningful, itās the id. So I want a sorted copy of this array of positions and for the longest time I kept corrupting my original array of positions. Oh well.
So now Iām copying the array like an animal, by hand.
ā Alex 2022-09-08 18:07 UTC
---
This should work:
ā r 2022-09-09 05:06 UTC
---
Thanks!
Iām still grappling with the issue because I keep reading sentences like the following:
A copy of the array will be automatically created when
An array variable is assigned to another array variable.
The following therefore works:
But in my case, Iām using slices, not arrays, and now this āautomatic copyingā no longer works:
Iāll now go and add the copy command in one or two places of my project. š
ā Alex 2022-09-09 06:44 UTC