TIL that field order in structs matter
Note the `struct with 88 pointer bytes could be 72` linter warning. If I change the order of the fields in the struct to this:
the warning goes away. From what I can tell, the lint rule called `fieldalignment` checks if the fields in a struct are ordered in an optimal way. What is the optimal way? Short version is all pointers should come first. I've never seen this before so it's something I'm interested in learning more about.
TIL about sync.WaitGroup in Golang
WaitGroup is useful when setting up graceful shutdown where multiple goroutines might be doing tasks and we want to wait for all of them to be completed before stopping the server.
Source: Let's Go Further by Alex Edwards and sync package docs
TIL what bare git repositories and git worktrees are
A bare repo, doesn't have our project files and only has the folders and files in the above image. When we clone a repo, if we add `--bare` to the clone command, we make a bare repo.
Why do this?
For one, we can clone off of a bare repo:
git clone --bare /home/ilango/aurelius aurelius_2
Note that the I'm cloning a repo from a local folder. This is useful for collaboration when we have a shared storage in a local network and don't want to host our project in the cloud.
What made me more interested in bare repos is worktrees. Git worktrees are one of the lesser known but coolest features. It allows us to have unfinished work in multiple branches at the same time, without having to use `git stash`.
For example, let's say you're in `feature-branch-1`, and are made aware of a bug in `main`. You have unstaged work in feature-branch-1, so you run `git stash`, checkout to main, fix the bug, come back to the feature branch and run `git stash pop`. With worktrees, we don't need to do all this.
Instead of a normal clone, do a bare clone, and run
git worktree add main main
Note: first "main" is the folder name, second "main" is the branch name. Also note, the main folder in the image. That's my main branch worktree.
This creates a main folder in your bare repo. Changing to this repo we can see that the main folder contains our main branch! We can do this for as many branches as we want and switch between them with different changes. We don't need bare repositories for using git worktrees but it keeps my folder structure cleaner.
More details here: https://git-scm.com/docs/git-worktree
TIL in Golang: Identifying Isograms & difference of squares
After I finished them, I checked the community solutions and realized how brute-forced, inefficient my solution was. But that's the process of learning.
By checking community solutions, I learned about two methods available in the standard library: IsLetter and ContainsRune!
TIL in Golang: Time, Type Conversion & Assertion, First class functions
Fortunately, time was the last concept I had to learn in the Go syllabus on Exercism. Now on to the other exercises, 1 or 2 a day. Also, it's time to dive into some projects from this project-based learning repo: https://github.com/practical-tutorials/project-based-learning#go
*SPOILERS*
Time: https://exercism.org/tracks/go/exercises/booking-up-for-beauty/solutions/ilango
Type Conversion & Assertion: https://exercism.org/tracks/go/exercises/sorting-room/solutions/ilango
First class functions: https://exercism.org/tracks/go/exercises/expenses/solutions/ilango
TIL in Golang: Interfaces & Errors
So there is no exceptions for error handling in Go. Instead errors are values of an interface called `error`. In order to learn errors, I had to learn interfaces.
I still need more practice on these two topics because I feel my understanding of them is a bit shaky. Anyways, here's my solution:
*SPOILERS*
https://exercism.org/tracks/go/exercises/the-farm/solutions/ilango
TIL in Golang: Regular Expressions
The exercise is parsing logs and cleaning up logs. We have to write a bunch of functions that does different cleaning up and organizing tasks.
*SPOILERS*
Solution: https://exercism.org/tracks/go/exercises/parsing-log-files/solutions/lbcosta
TIL in Golang: Methods & Runes
Pretty simple exercises but took me a bit of time to figure out a few issues, especially in runes.
*SPOILERS*
Runes: https://exercism.org/tracks/go/exercises/logs-logs-logs/solutions/ilango
Methods: https://exercism.org/tracks/go/exercises/elons-toys/solutions/ilango
TIL in Golang: Pointers
Anyways, today's Golang lesson was Pointers. The exercise was to build a simplified digital vote counting system for a students' association president election.
Here's my solution (SPOILERS): https://exercism.org/tracks/go/exercises/election-day/solutions/ilango
TIL in Golang: Range Iteration & Type Definitions
Today's lessons were Range Iteration and Type Definitions. Both have a common exercise, which was to generate a simple chessboard and do small calculations on it.
Here's my solution (SPOILERS): https://exercism.org/tracks/go/exercises/chessboard/solutions/ilango