Understand Go toolchain directive or your money back

With this compatibility support, the latest Go toolchain should always be the best, most secure implementation of an older version of Go.
https://go.dev/doc/go1.21#tools

You’ll never have to manually download and install a Go toolchain again. The go command will take care of it for you. https://go.dev/blog/toolchain

Go 1.21 added a new toolchain directive to go.mod. I found it challenging to fully understand its behavior, since there are several lengthy docs on the subject.
So here is a concise overview with examples:

Read more

Notes on go error hanling

TL;DR

Read Chapter 5.4 in The Go Programming Language by Alan A. A. Donovan and Brian W. Kernighan. In just two pages, the original designers of the language explain the essence of Go error handling.

The book was published in 2015, before the Go standard library added additional convenience functions in 2019. So, also read this blog post: Working with Errors in Go 1.13.

For some examples, check out: https://tour.ardanlabs.com/tour/error-handling/1
You can also skim through the “Extra reading” section, but keep in mind the age of those posts.

Read more

Confused about implicit type promotion in C

The following code compiles and prints the message.

#include <stdio.h>

char test_char = 'a';
int test_int = 97;

int main(void)
{
    if (test_char == test_int)
    {
        printf("%s\n", "compared int and char with no issues");
    }
}

Even if we compile it with all possible warnings enabled:

/usr/bin/gcc -Wall -Wextra -Wconversion -Werror -Wfloat-equal -Wmissing-noreturn -Wmissing-prototypes -Wsequence-point -Wshadow -Wstrict-prototypes -Wunreachable-code -pedantic -std=c18 -ggdb3

However, no warning or errors are printed, even though we compare int to char.

Read more