194 Followers
185 Following
475 Posts

#infosec enthusiast • #golang dev & trainer • contributor to the Go project • minimalist • chaotic good • trying to make sense of the Web • he/him
Free Go course: https://github.com/jub0bs/go-course-beginner

Free 🇵🇸! Leave 🇱🇧 alone!

Websitehttps://jub0bs.com
Blueskyhttps://bsky.app/profile/jub0bs.com
GitHubhttps://github.com/jub0bs
Xhttps://x.com/login?redirect_after_login=https%3A%2F%2Fx.com%2Flogout%3Fredirect_after_logout%3Dhttps%253A%252F%252Fjub0bs.com

I love how the conjunction of #golang's modules system and build constraints lets you have your cake and eat it too! 🍰

You can let users of your library take advantage of the bleeding edge if they so wish without cutting off one of the currently supported Go toolchains.

When something tantalising gets merged at tip, you can put code that relies on it in a file guarded by a //go:build go1.27 build constraint and its pre-1.27 counterpart in a file guarded by a //go:build !go1.27 build constraint. No need to update your go.mod's go directive.

Even when you cannot eliminate all bounds checks within a loop, eliminating most of them may benefit performance. 😉
#golang

https://go-review.googlesource.com/c/go/+/759100

Unfortunately, this proposal would require a breaking change. Therefore, I've decided to retract it.

Paradoxically (perhaps), as the Go compiler becomes better at eliminating bounds checks, attacker-reachable panics due to incorrect programmer assumptions about indices become easier to find.

#golang

Fewer bounds checks in #golang thanks to Youlin Feng: https://go-review.googlesource.com/c/go/+/719881
I've just filed a proposal to make bool an ordered type (compatible with operators <, <=, >, and >=) in #golang: https://github.com/golang/go/issues/78027
proposal: spec: make bool an ordered type · Issue #78027 · golang/go

Go Programming Experience Experienced Other Languages Experience Python, Haskell, JavaScript, C Related Idea Has this idea, or one like it, been proposed before? Does this affect error handling? Is...

GitHub

#golang quiz: What happens if you try to compile and run the following program?

package main

import (
"fmt"
"math"
)

func main() {
fmt.Println(int(math.NaN()))
}

It prints 0.
18.2%
It prints -1.
9.1%
It panics.
9.1%
Compilation fails.
18.2%
Something else.
45.5%
Poll ended at .

🚀 "spec: generic methods for Go" has been accepted!

You will soon (1.27?) be able to declare (on concrete types only) methods that introduce type parameters, i.e. type parameters other than the ones (if any) that come from the method's receiver.

Since the inception of generics in Go (1.18), methods could not introduce type parameters. You had to resort to declaring package-scoped functions instead; code organisation and ergonomics typically suffered.

The proposal lifts this restriction for concrete types (though not for interface types).

https://github.com/golang/go/issues/77273#issuecomment-3962618141

#golang

spec: generic methods for Go · Issue #77273 · golang/go

Proposal: Generic Methods for Go A change of view. Background For clarity, in the following we use the term concrete method (or just method when the context is clear) to describe a non-interface me...

GitHub
(If you get a timeout on the playground, try again, or try running the program locally.)

A friendly reminder that a Go program doesn't need an import of the "unsafe" package to undermine the language's type system; a synchronisation bug may be enough: https://go.dev/play/p/L0_ZrqS2-4a

#golang

Go Playground - The Go Programming Language