Rohit Sachdeva

@rsachdeva
1 Followers
7 Following
15 Posts
#Golang #Go #Ziglang #Zig #Rustlang #Rust Senior Backend & Systems Software Engineer https://github.com/rsachdeva

Lock() in sync.Mutex / sync.RWMutex vs RLock() in sync.RWMutex:
Lock() — blocks readers AND writers
RLock() — blocks writers only, does NOT block other readers

Use RWMutex RLock() when reads >> writes.
#golang #concurrency

sync.Once's .Do and sync.OnceFunc both take func() — no return.
So the result has to live somewhere: a separate struct field you write to as a side effect.

sync.OnceValue takes func() T — the return value IS the cache. No extra field.

#golang #concurrency

time.After(d): Concurrency tool. Sets up a background timer and returns a channel.

t.After(u): Date/time method. Instant boolean comparison to check if timestamp t occurs after timestamp u.

#Golang time package

Go proverb: “errors are values” means “errors are values that implement the `error` interface.”

#Golang

Release notes are up!

I wish it went without saying, but these notes are completely written by hand.

https://ziglang.org/download/0.16.0/release-notes.html

0.16.0 Release Notes ⚡ The Zig Programming Language

Go's time package has two sides:
date/time handling
Timer-based concurrency tools:

time.NewTimer(d)
timer.Stop()
timer.Reset(d)
time.After(d)
time.AfterFunc(d, f)
time.NewTicker(d)
ticker.Stop()
time.Tick(d)

#golang #concurrency

Go goroutine stack dumps show a bracketed state like [chan send] or [chan receive]: that means blocked. The full list lives in src/runtime/runtime2.go as waitReason constants. Not documented anywhere else. #golang https://github.com/golang/go/blob/fa238516b782bd1f233e85b719b7ab90889a5634/src/runtime/runtime2.go#L1221
go/src/runtime/runtime2.go at fa238516b782bd1f233e85b719b7ab90889a5634 · golang/go

The Go programming language. Contribute to golang/go development by creating an account on GitHub.

GitHub
Check out the official list of Go replacements: pkg.go.dev/golang.org/x/tools/go/analysis/passes/modernize
From Go 1.26+, `go fix` helps you with each of these replacements automatically! #golang

#golang
• for {} — Header omission = true.
• switch {} — Header omission = true (if/else chain).

#ziglang
• while (true) {} — Header requires explicit true.
• if / else — Standard conditionals; switch requires expression.

It’s great to see the #golang compiler using stack allocations to kill those noisy 1, 2, and 4-item heap allocations—even for escaping slices.
Optimized performance, automatically. https://go.dev/blog/allocation-optimizations
become allocation aware #ziglang
Allocating on the Stack - The Go Programming Language

A description of some of the recent changes to do allocations on the stack instead of the heap.