oleg_log
1.77K subscribers
1.86K photos
130 videos
9 files
2.78K links
Shelter for antisocial programmers "Oleg"

halp: @olegkovalov
web: https://olegk.dev
fov: @oleg_fov
chat: @oleg_log_blabla
podcast: @generictalks
Download Telegram
N900 <3

The most desirable phone of my childhood.

https://yaky.dev/2025-12-11-nokia-n900-necromancy/
I think I can confidently say that the following pattern is wrong in all cases. B ut it works… until it doesn’t.

{
...
for {
go process(...)
}

// some logic around atomicCounter waiting for a zero
}

func process(...) {
atomicCounter.Add(1)
defer atomicCounter.Add(-1)
}


Not convinced? Let's rewrite with sync.WaitGroup:

{
...
for {
go process(...)
}

// some logic around sync.WaitGroup.Wait()
}

func process(...) {
wg.Add(1)
defer wg.Done()
}


Even if this still doesn't convince you, this issue is documented in go vet:

https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/waitgroup

The problem is that atomicCounter is updated inside a goroutine that happens instantly but there is no real guarantee that this will happen instantly.
The runtime may schedule the goroutine later, so the counter might not be incremented yet.

Voila, now you've to debug why you missing data that was consumed but not processed!

And the fix is quite simple: any goroutine management should happen before the goroutine start:

{
...
for {
wg.Add(1)
go process(...)
}

// some logic around sync.WaitGroup.Wait()
}

func process(...) {
defer wg.Done()
}
I made smth (tbh, I just open-sourced 1 internal pkg), 3 funcs but used dozens of times across the codebase.

https://github.com/cristalhq/ordx

cmp := ordx.RankCmp([]string{"low", "medium", "high"})

fmt.Println(cmp("low", "high"))
fmt.Println(cmp("high", "low"))
fmt.Println(cmp("medium", "medium"))

// Output:
// -1
// 1
// 0


Fuzz and race tests are always welcome.
Gods Gophers gave you an arbitrary order of top-level definitions yet you still write code as if it were C :(

Or am I the one who prefers exported definitions first and unexported later?
Any good cloud-init configs for a small server for pet projects? Thanks in advance.

(links to blogs are also appreciated)
Cool one. Especially the name.

https://vitaut.net/posts/2025/faster-dtoa/
lol
>>> chr(sum(range(ord(min(str(not()))))))
'ඞ'
Oh no
Jokes aside. Any recommendations on image resizing in Go?

Ideally without CGO, might be a standalone service(systemd) or as a proxy.

Thanks in advance.
I was today years old when I have discovered Scala2 implicit parameters.

Absolutely disgusting. Like ultimately pro max disgusting.

The funniest thing (to me only?) it got redesigned in Scala 3 with „given” keyword.
Good interview question, happened to me once iirc.

Ok, to paraphrase: it’s was a good question to kick off a deep and thoughtful discussion about language and program design in general.

For someone senior level and higher with a different background, it’s a great topic to discuss.
Go ahead, self-host Postgres

Love this "The real operational complexity" paragraph.

https://pierce.dev/notes/go-ahead-self-host-postgres