This blog is updated more than the home page might imply,
but only the most intersting stuff gets posted on the home page.
30 Jan 2023
Version 5 of the excellent pgx
library for Go pulls in a number of useful functions from jackc's
own pgxutil library.
This is very nice, because one can basically almost always use
the Query() method of a pgx.Conn,
pgxpool.Pool, pgx.Tx, or pgxpool.Tx,
and then just hand the resulting pgx.Rows
into collectors such as pgx.CollectRows() and pgx.CollectOneRow(),
and into scanners such as pgx.RowTo(), pgx.RowToAddrOf(),
This inspired me to write my own helper functions, because there were some
needs I had that are not currently covered by pgx 5. These helper functions
now live in a Go module named pgextras!
pgxtras allows one to select one row and not get an error from pgx
when nothing is found: the same way one does not get an error when
no rows are returned at a psql prompt.
pgxtras also has a more lenient version of a row scanner where
snake case column names are more easily/automatically mapped to
camel case Go struct field names.
The book Hacker's Delight has a pretty neat way of counting
the 1-bits in an integer. But my exploration shows that modern Intel CPUs
have an instruction that do that for you, and that Go's math/bits library
takes advantage of that instruction. Nonetheless, I leave notes
that spell out the Hacker's Delight solution as obvoiusly as I can.
I've been reading parts of Katherine Cox-Buday's Concurrency in Go,
and I think this incomplete list of facts about channels and select statements
is useful. A full table of channel operation/state/result is on page 75;
these notes are just for me and whoever else may find them useful
a write to a full channel blocks until the channel is read from
a read from an empty channel blocks until the channel is writen to
a closed channel can be read from an infinite number of times
a write to a closed channel panics
all reads/writes are considered simultaneously for readiness
when no channels are ready, the entire select statement blocks
when more than one channel is ready, one will be chosen at random
defualt, if present, is run when all channels are blocked